dcsimg
save image as jpg with com.sun.image.codec.jpeg
1 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   Andreea_Francu
Posted On:   Tuesday, April 24, 2001 03:31 PM

I'm trying to save the canvas as a .jpg file using the JPGImageEncoder from com.sun.image.codec.jpeg package; everything seems to work right, but when I open the .jpg file all I get is a black rectangle. Any idea why? Here's some code: Dimension size = canvas_.getSize(); BufferedImage image = new BufferedImage(size.width, size.height, BufferedImage.TYPE_INT_RGB); try { OutputStream out = new FileOutputStream("pic.jpg"); JPEGImageEncoder encoder = JPEGCodec.createJPEGEncoder(out); encoder.encode(image); out.close(); } catch (Exception e) { System.out.println(e); }    More>>

I'm trying to save the canvas as a .jpg file using the JPGImageEncoder from com.sun.image.codec.jpeg package;
everything seems to work right, but when I open the .jpg file all I get is a black rectangle.
Any idea why?

Here's some code:

Dimension size = canvas_.getSize();
BufferedImage image = new BufferedImage(size.width, size.height, BufferedImage.TYPE_INT_RGB);
try {
OutputStream out = new FileOutputStream("pic.jpg");
JPEGImageEncoder encoder = JPEGCodec.createJPEGEncoder(out);
encoder.encode(image);
out.close();
}
catch (Exception e) { System.out.println(e); }

   <<Less

Re: save image as jpg with com.sun.image.codec.jpeg

Posted By:   AlessandroA_Garbagnati  
Posted On:   Tuesday, April 24, 2001 03:45 PM

Hi,

Well, if that is the code, I think that it's ok. The image you're saving is empty and I think that the default background color for a INT_RGB type it's black.
About | Sitemap | Contact