I.ve problem with java image processing.I've to convert 2d array into image.I'm using the loadPixels function, but it doesen't work.The Image is never shown on the label.
Please help, here is the code of the loadPixels function:
public static void loadPixels(JLabel label, int[][] pixels) {
// 1. convert to 1-d array
int width = pixels.length;
int height = pixels[0].length;
int i=0; // index into new pixarray
int[] pixarray = new int[width*height];
for (int y=0; y<height; y++)
for (int x=0; x<width; x++)
// these are stored y-major!
pixarray[i++] = pixels[x][y];
// 2. convert 1-d array into Image*/
MemoryImageSource source = new MemoryImageSource(width,height,pixarray,0,width);
imageto=label.createImage(source); // imageto is declared in the top of the class as "private static Image"
// 3. store Image in the JLabel
ImageIcon imic=new ImageIcon(imageto);
//imic=image;
label.setIcon(imic);
}
Any help would be greatly appreciated.
Thanks,
Nina