aspose file tools
The moose likes Java in General and the fly likes write an existing image to disk Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


JavaRanch » Java Forums » Java » Java in General
Reply Bookmark "write an existing image to disk" Watch "write an existing image to disk" New topic
Author

write an existing image to disk

Kay Tracid
Ranch Hand

Joined: Mar 06, 2002
Posts: 148
Hi,
I want to save an image to a drive. I loaded it with getToolkit().getImage(..). I MUST use an Image because I want to scale it before saving. Can you help me please, I tried ImageIO from the jdk 1.4 but I find only a solution for BufferedImage. This I can't scale like
Image img;
img = img.getScaledInstance(400, 271, Image.SCALE_SMOOTH);
this does not work:
File f = new File("name.jpg");
BufferedImage bimage = new BufferedImage(..);
bimage = bimage.getScaledInstance(400, 271, Image.SCALE_SMOOTH); // <- problem
ImageIO.write(bImage, "jpg", f);

Thanks!!!
Kay Tracid
Ranch Hand

Joined: Mar 06, 2002
Posts: 148
PLEEEEEEAAAAAAAAAAAAASSSSEEEEE.......
Kay Tracid
Ranch Hand

Joined: Mar 06, 2002
Posts: 148
the solution:
Image medImage = getToolkit().getImage(..);
medImage = medImage.getScaledInstance(400, 277, Image.SCALE_SMOOTH);
BufferedImage medBImage = new BufferedImage(400, 277, BufferedImage.TYPE_INT_RGB);
add medImage to a mediatracker!
medBImage.createGraphics().drawImage(medImage,0,0,null);
File f = new File("image.jpg");
try
{
ImageIO.write(medBImage, "jpg", f);
}
catch(Exception e)
{
System.out.println(e);
}
Easy or ?
 
 
subject: write an existing image to disk
 
developer file tools