Skip to main content

compression not working properly on PNG GIF images

1 reply [Last post]
quilla_b
Offline
Joined: 2006-09-26

hi, how come when i compress GIF and PNG images... the file size does not reduce...instead it gets bigger?

here's my code for GIF:

GIFImageWriter writer = (GIFImageWriter) writers.next();

// Prepare output file
ImageOutputStream ios = ImageIO.createImageOutputStream(out);
writer.setOutput(ios);

// Set the compression quality
ImageWriteParam param = writer.getDefaultWriteParam();
if (quality >= 0) {
param.setCompressionMode(ImageWriteParam.MODE_EXPLICIT);
param.setCompressionType("LZW");
System.out.println("\nGIF compressiontType="+param.getCompressionType());
param.setCompressionQuality(quality);
}

writer.write(null, new IIOImage(bimage, null, null), param);

code for PNG:

ImageWriter writer = (ImageWriter) writers.next();

// Prepare output file
ImageOutputStream ios = ImageIO.createImageOutputStream(out);
writer.setOutput(ios);

// Set the compression quality
ImageWriteParam param = writer.getDefaultWriteParam();
if (quality >= 0) {
param.setCompressionMode(ImageWriteParam.MODE_EXPLICIT);
param.setCompressionType("DEFAULT");
param.setCompressionQuality(quality);
}

writer.write(null, new IIOImage(bimage, null, null), param);

Message was edited by: quilla_b

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
Brian Burkhalter

The PNG problem might have been addressed recently:

https://jai-imageio-core.dev.java.net/issues/show_bug.cgi?id=77

Please try with the most recent jai-imageio daily build.

As for the GIF issue, I've no idea. Would you please post a *complete* test
case?

Thanks,

Brian

On Wed, 27 Sep 2006, jai-imageio@javadesktop.org wrote:

> hi, how come when i compress GIF and PNG images... the file size does not reduce...instead it gets bigger?
>
> here's my code for GIF:
> [i]
> GIFImageWriter writer = (GIFImageWriter) writers.next();
>
> // Prepare output file
> ImageOutputStream ios = ImageIO.createImageOutputStream(out);
> writer.setOutput(ios);
>
> // Set the compression quality
> ImageWriteParam param = writer.getDefaultWriteParam();
> System.out.println("\nGIF canWriteCompressed="+param.canWriteCompressed());
> if (quality >= 0) {
> param.setCompressionMode(ImageWriteParam.MODE_EXPLICIT);
> param.setCompressionType("LZW");
> System.out.println("\nGIF compressiontType="+param.getCompressionType());
> param.setCompressionQuality(quality);
> }
>
> writer.write(null, new IIOImage(bimage, null, null), param);[/i]
>
>
> code for PNG:
>
> [i]ImageWriter writer = (ImageWriter) writers.next();
>
> // Prepare output file
> ImageOutputStream ios = ImageIO.createImageOutputStream(out);
> writer.setOutput(ios);
>
> // Set the compression quality
> ImageWriteParam param = writer.getDefaultWriteParam();
> System.out.println("\nPNG canWriteCompressed="+param.canWriteCompressed());
> System.out.println("\nPNG isCompressionLossless="+param.isCompressionLossless());
> if (quality >= 0) {
> param.setCompressionMode(ImageWriteParam.MODE_EXPLICIT);
> param.setCompressionType("FILTERED");
> System.out.println("\nPNG compressiontType="+param.getCompressionType());
> param.setCompressionQuality(quality);
> }
>
> writer.write(null, new IIOImage(bimage, null, null), param);[/i]
> [Message sent by forum member 'quilla_b' (quilla_b)]
>
> http://forums.java.net/jive/thread.jspa?messageID=157097
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: interest-unsubscribe@jai-imageio.dev.java.net
> For additional commands, e-mail: interest-help@jai-imageio.dev.java.net
>
>

----------------
Brian Burkhalter
Java Media, Imaging, and Graphics
Sun Microsystems, Inc.

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
This email message is for the sole use of the intended recipient(s)
and may contain confidential and privileged information. Any
unauthorized review, use, disclosure or distribution is prohibited.
If you are not the intended recipient, please contact the sender by
reply email and destroy all copies of the original message.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

---------------------------------------------------------------------
To unsubscribe, e-mail: interest-unsubscribe@jai-imageio.dev.java.net
For additional commands, e-mail: interest-help@jai-imageio.dev.java.net