JPG compression/colors... is there a way to set these parameters?!?!?!?!
1 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   Kimberly_Hendershot
Posted On:   Thursday, August 15, 2002 09:24 AM

I'm using Java 1.4 ImageI/O to create a JPG from a buffered image and save the JPG to a file. It works okay, except I had thought that it would save the JPG with no compression if none was specified. But it was compressed... So, I got an ImageWriter for JPG and tried this bit of code: JPEGImageWriteParam iwparam = new JPEGImageWriteParam(null); iwparam.setCompressionMode(ImageWriteParam.MODE_EXPLICIT); < iwparam.setCompressionQuality(compressionQuality); where compressionQuality is set to 0 so that there would be NO COMPRESSION. It looks better, but is still fuzzy. And my colors are all darker than they should be. The buffered image is defined as such: BufferedImage bi = ne   More>>

I'm using Java 1.4 ImageI/O to create a JPG from a buffered image and save the JPG to a file. It works okay, except I had thought that it would save the JPG with no compression if none was specified. But it was compressed... So, I got an ImageWriter for JPG and tried this bit of code:



JPEGImageWriteParam iwparam = new JPEGImageWriteParam(null);

iwparam.setCompressionMode(ImageWriteParam.MODE_EXPLICIT); <

iwparam.setCompressionQuality(compressionQuality);



where compressionQuality is set to 0 so that there would be NO COMPRESSION. It looks better, but is still fuzzy. And my colors are all darker than they should be. The buffered image is defined as such:



BufferedImage bi = new BufferedImage(390,420,BufferedImage.TYPE_INT_RGB);



Is there another way to set some parameters or anything so that there is no compression and the colors will be right???


I cannot use GIF b/c ImageI/O does not support writing that format. I thought about using PNG, but am unsure of browser support for this.


Any suggestions will be greatly appreciated!
Thanks

   <<Less

Re: JPG compression/colors... is there a way to set these parameters?!?!?!?!

Posted By:   Matthew_Bishop  
Posted On:   Sunday, September 1, 2002 06:58 PM


I've only used the Independent JPEG Group's (IJG) C library, so I'm not sure if this holds for the Java version. In the C version, a compression quality of 90 gives a 90% correct image, not a 90% compressed file. It may be that 0 compressionQuality is attempting maximum compression. You really shouldn't be getting a fuzzy JPEG at low compression.




IIRC, JPEG isn't normally used for lossless encoding; IJG's library doesn't even do it. A compression quality of 95 should be very clean and reasonably small; 80 is still good but smaller yet. If you need to ensure you have an *exact* copy of the image, you must use PNG, at the expense of 10x larger files. PNG should be supported in IE since version 4 (but no transparency support), and Netscape since around v.4 as well.




Hope that helps.

About | Sitemap | Contact