JPEG in TIFF encoding

馋奶兔 提交于 2020-01-04 10:42:54

问题


I do this steps:

TIFFEncodeParam tep = new TIFFEncodeParam();

tep.setCompression(TIFFEncodeParam.COMPRESSION_JPEG_TTN2);

BufferedImage buff = new BufferedImage(newimage.getWidth(null),
                                                   newimage.getHeight(null),
                                                   BufferedImage.TYPE_BYTE_BINARY);
//newimage is an awt image

buff.createGraphics().drawImage(newimage, 0,0,null);

ParameterBlock outPB = new ParameterBlock();

outPB.addSource(buff);
outPB.add("myjpegfile.jpg");
outPB.add("tiff");
outPB.add(tep);

PlanarImage outPI = JAI.create("filestore",outPB);

Here I get:java.lang.Error: JPEG-in-TIFF encoding supported only for 8-bit sampl es and either 1 (grayscale) or 3 (RGB or YCbCr) samples per pixel.

This because I need to have maximum compression in jpeg file for monochromatic image. I'm able to write tiff (24Kb), and jpeg (212Kb) (A4 page size 200dpi BW) but jpeg is too huge.

What does it mean this error? What is 8-bit samples?

Thx.


回答1:


This means that JPEG--in-TIFF only supports 8-bit greyscale (= 1 sample with 8 bits per pixel) or 24-bit color images (= 3 samples with 8 bits per pixels).

TYPE_BYTE_BINARY represents a black/white picture (= 1 sample with 1 bit per pixel). You'd want to use TYPE_BYTE_GRAY instead.




回答2:


There is no such thing as a B&W jpg, assuming by B&W you mean an image with 1 bit per pixel, each pixel being either black, or white. And typically, when you convert a B&W scan to grayscale and then save it with JPEG compression, it is much larger than saving the original B&W image in a compressed format like TIFF or PNG. The small sharp monochrome edges in a B&W scan are about the worst possible thing for JPEG to compress.

You should re-examine the file you are trying to duplicate and understand better what its actual format is. Maybe it is a JBIG2 file? That is a B&W compression format that works extremely well.

Another possibility, which I've seen, is that you have a file with extension 'jpg' that is actually in TIFF or PNG format. Look at the first few bytes of the file and use that signature to identify the format of the file e.g. here. If it is a JPEG, get more details using a program like JPEGsnoop by Calvin Hass. (No personal relationship, I'm just a happy user.) If it's actually a TIFF, you can get more details with AsTiffTagViewer by Aware Systems.



来源:https://stackoverflow.com/questions/6760524/jpeg-in-tiff-encoding

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!