Results 1 to 2 of 2
  1. #1
    Nina* is offline Member
    Join Date
    Oct 2008
    Rep Power

    Default 2d array to image

    Hello, 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);
    Any help would be greatly appreciated.



  2. #2
    Supamagier is offline Senior Member
    Join Date
    Aug 2008
    Rep Power


    Any error message(s)?
    I die a little on the inside...
    Every time I get shot.

Similar Threads

  1. Canvas Image popups another image (SWT)
    By SpaceY in forum New To Java
    Replies: 2
    Last Post: 11-11-2008, 01:25 PM
  2. Array Reflection: Multi Array Reflection
    By Java Tip in forum java.lang
    Replies: 0
    Last Post: 04-23-2008, 08:08 PM
  3. set coordinate to an image
    By nuur in forum AWT / Swing
    Replies: 2
    Last Post: 04-01-2008, 08:08 AM
  4. Replies: 0
    Last Post: 01-08-2008, 05:29 PM
  5. 2D Array to image
    By fred in forum Java 2D
    Replies: 1
    Last Post: 07-24-2007, 01:52 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts