Saving a BufferedImage to a file
2 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   Nathan_Levis
Posted On:   Thursday, August 16, 2001 04:15 PM

I would like to know how to write a BufferedImage to a file. I went out to sun and looked at the Java Image I/O API and there is a class ImageIO that would work great, but I cannot find out how to download the API. I imagine that there has to be a way from the standard components of Java2 to write out an image that one creates. I appreciate any help that you can give.


Thanks, Nate

Re: Saving a BufferedImage to a file

Posted By:   AlessandroA_Garbagnati  
Posted On:   Thursday, August 16, 2001 11:41 PM

Nathan,


This is a piece of a method I've wrote time ago:


public static final boolean jpegWriteFile(BufferedImage image, File jpegFile, float quality) {

boolean retVal = false;
BufferedOutputStream bos = null;

try {
JPEGEncodeParam eP = JPEGCodec.getDefaultJPEGEncodeParam(image);
eP.setQuality(quality, true);
bos = new BufferedOutputStream(new FileOutputStream(jpegFile));
JPEGImageEncoder encoder = JPEGCodec.createJPEGEncoder(bos);
encoder.encode(image, eP);
retVal = true;
}
catch (Exception e) {
// do your error checking
}
finally {
try { bos.close(); } catch (Exception ee) {}
}

return retVal;
}

Re: Saving a BufferedImage to a file

Posted By:   Naveed_Azhar  
Posted On:   Thursday, August 16, 2001 11:06 PM

Hi there

I replied same question yesterday. That will be answer to your question also

http://www.jguru.com/forums/view.jsp?EID=477793


naveed@hotmail.com
About | Sitemap | Contact