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:
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:
Quote:
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