Results 1 to 1 of 1
  1. #1
    Sepho is offline Member
    Join Date
    Aug 2009
    Posts
    1
    Rep Power
    0

    Default Reconstruct image from a pixel array

    Hi everybody!

    I'm working in a proyect that work with images. I loaded image from file and decode it in a int array of pixels. After manipulate that pixels I want to reconstruct the image, to save it in hard disk. I've done that:

    Java Code:
    Image newImg;
    
    newImg = createImage(new MemoryImageSource(imgCols, imgRows, pixelsNewImg, 0, imgCols));
    
    File output = new File("/home/sepho/myfile.jpg");
    
    try {
      [b]if (ImageIO.write((RenderedImage) newImg, "jpg", output))[/b] {
           System.out.println("Image stored...");
      }
         } catch (IOException ex) {
              Logger.getLogger(Main.class.getName()).log(Level.SEVERE, null, ex);
         }
    Where imgCols and imgRows are the columns and rows of the original image, and pixelsNewImg is the int array of pixels.

    If I try to run, I get the next error:

    Exception in thread "main" java.lang.ClassCastException: sun.awt.image.ToolkitImage cannot be cast to java.awt.image.RenderedImage
    This is in the bold line above. Any idea?

    Thanks for all, and sorry for my english! :P
    Last edited by Sepho; 08-29-2009 at 12:36 AM.

Similar Threads

  1. Scanning Image Pixel by Pixel
    By the_transltr in forum Advanced Java
    Replies: 5
    Last Post: 08-28-2012, 04:01 PM
  2. Replies: 14
    Last Post: 04-10-2009, 08:46 AM
  3. Pixel Array?
    By AndrewM16921 in forum New To Java
    Replies: 4
    Last Post: 04-03-2009, 12:08 AM
  4. how to get rgb value each pixel of an image file
    By tOpach in forum New To Java
    Replies: 1
    Last Post: 03-28-2009, 04:38 PM
  5. Replies: 1
    Last Post: 07-17-2007, 04:10 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
  •