Can I change the compression algorithm used by Java ImageWriter when creating JPEG?

Or, alternatively, is there a better library for handling compression?

Let me preface this with what I already understand: (1) JPEG is lost - it will not look the same as the input file. (2) I can set the compression quality setting to a value from 0.0 to 1.0, as I did in the code below.

I take a BufferedImage and convert it to JPEG and notice that the Java ImageWriter.write () method creates sub-paired results for JPEG images (Photoshop Save for Web as an example).

My code looks something like this:

// img is a BufferedImage, here
ImageWriter writer = ImageIO.getImageWritersByFormatName("jpeg").next();
ImageWriteParam iwp = writer.getDefaultWriteParam();
iwp.setCompressionMode(ImageWriteParam.MODE_EXPLICIT);
iwp.setCompressionQuality(.75f);

IIOImage image = new IIOImage(img, null, null);
ByteArrayOutputStream byteArrayOut = new ByteArrayOutputStream();
writer.setOutput(ImageIO.createImageOutputStream(byteArrayOut));
writer.write(null, image, iwp);
writer.dispose();

, "1.0" , , JPEG.

... -, . , - , .

, JPEG (PNG ), . . , JPEG JPEG , , .

+5
1

"Java ImageWriter.write() - JPEG ( Photoshop" ", ).

, , , Java imageio, .

, , : JPEG , , . , , JPEG. , .

, , - ( ), . - , , . this.

Calvin Hass JPEG JPEGSnoop, http://www.impulseadventure.com. ps75.jpg, , :

 Component[1]: ID=0x01, Samp Fac=0x11 (Subsamp 1 x 1), Quant Tbl Sel=0x00 (Lum: Y)
 Component[2]: ID=0x02, Samp Fac=0x11 (Subsamp 1 x 1), Quant Tbl Sel=0x01 (Chrom: Cb)
 Component[3]: ID=0x03, Samp Fac=0x11 (Subsamp 1 x 1), Quant Tbl Sel=0x01 (Chrom: Cr)

, . , 100.jpg 75.jpg :

 Component[1]: ID=0x01, Samp Fac=0x22 (Subsamp 1 x 1), Quant Tbl Sel=0x00 (Lum: Y)
 Component[2]: ID=0x02, Samp Fac=0x11 (Subsamp 2 x 2), Quant Tbl Sel=0x01 (Chrom: Cb)
 Component[3]: ID=0x03, Samp Fac=0x11 (Subsamp 2 x 2), Quant Tbl Sel=0x01 (Chrom: Cr)

, , , .

, / , , , .

, IMO, , , . , , imageio ImageWriter (, , com.sun.imageio.plugins.jpeg.JPEGImageWriter), , ImageWriter.

, , Java ImageWriter, ImageWriter . , JEPG. Java JpegEncoder, James R. Weeks, . , , .

: JPEGSnoop 75% JPEG, , 92%. Calvin Hass , Photoshop :

, Photoshop CS2 JPEG JPEG:

Photoshop Save As Quality 0-6 - 2x2 Chroma Subsampling
Photoshop Save As Quality 7-12 - 1x1 No Chroma Subsampling
Photoshop Save For Web Quality 0-50 - 2x2 Chroma Subsampling
Photoshop Save For Web Quality 51-100 - 1x1 No Chroma Subsampling

Java, JPEG.

+5

All Articles