|
copy image/imageicon into a file on disk
I have created an imageIcon. I want to copy it into a file on the disk.
I have file on my disk (named : abc.jpg). I picked up the file and stored it in an imageicon using the code :
ImageIcon i=new ImageIcon("abc.jpg");
Then i did some processing on the imageicon "i" using the method :
ImageIcon process(ImageIcon)
The process method returned an imageicon which i stored into the variable "new_i" of type ImageIcon like this:
ImageIcon new_i=process(i);
Now i want to store this new_i ImageIcon into the disk (with named suppose : new_abc.jpg)
How do i do that?
Well, i tried it out after a lot of research in this way :
Image img = new_i.getImage();
BufferedImage bi = new BufferedImage(img.getWidth(null),img.getHeight(nul l), BufferedImage.TYPE_BYTE_ARGB );
ImageIO.write(bi, "jpg", new File("new_abc.jpg"));
The above code creates the file "new_abc.jpg" and just copies the structure of the image icon. From structure, i mean to say, it creates a black image with the size same as "abc.jpg".
If you can identify the mistake in the above code then please let me know. Or else if you know some other method for copying an image into a file, the please reply.
|