Results 1 to 2 of 2
Thread: 2d array to image
- 10-01-2008, 01:14 PM #1
Member
- Join Date
- Oct 2008
- Posts
- 1
- Rep Power
- 0
2d array to image
Hello,
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:
Java Code: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); }
Thanks,
Nina
- 10-01-2008, 04:08 PM #2
Senior Member
- Join Date
- Aug 2008
- Posts
- 384
- Rep Power
- 13
Similar Threads
-
Canvas Image popups another image (SWT)
By SpaceY in forum New To JavaReplies: 2Last Post: 11-11-2008, 01:25 PM -
Array Reflection: Multi Array Reflection
By Java Tip in forum java.langReplies: 0Last Post: 04-23-2008, 08:08 PM -
set coordinate to an image
By nuur in forum AWT / SwingReplies: 2Last Post: 04-01-2008, 08:08 AM -
Converting multiple banded image into single banded image... Image enhancement
By archanajathan in forum Advanced JavaReplies: 0Last Post: 01-08-2008, 05:29 PM -
2D Array to image
By fred in forum Java 2DReplies: 1Last Post: 07-24-2007, 01:52 AM
Bookmarks