TIFF 编码中的 JPEG
我执行以下步骤:
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);
这里我得到:java.lang.Error: JPEG-in-TIFF编码仅支持8位样本 es 和每个像素 1 个(灰度)或 3 个(RGB 或 YCbCr)样本。
这是因为我需要对单色图像的 jpeg 文件进行最大压缩。 我可以写 tiff (24Kb) 和 jpeg (212Kb)(A4 页面大小 200dpi BW),但 jpeg 太大了。
这个错误是什么意思?什么是 8 位样本?
谢谢。
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
这意味着 JPEG-in-TIFF 仅支持 8 位灰度(= 1 个样本,每像素 8 位)或 24 位彩色图像(= 3 个样本,每像素 8 位)。
TYPE_BYTE_BINARY 表示黑白图片(= 1 个样本,每像素 1 位)。您想改用 TYPE_BYTE_GRAY 。
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.
不存在黑白 jpg 之类的东西,假设黑白是指每个像素 1 位的图像,每个像素要么是黑色,要么是白色。通常,当您将黑白扫描转换为灰度,然后使用 JPEG 压缩保存时,它比以 TIFF 或 PNG 等压缩格式保存原始黑白图像要大得多。黑白扫描中的小而尖锐的单色边缘对于 JPEG 压缩来说可能是最糟糕的事情。
您应该重新检查您尝试复制的文件并更好地了解其实际格式。也许它是一个 JBIG2 文件?这是一种效果非常好的黑白压缩格式。
我见过的另一种可能性是,您有一个扩展名为“jpg”的文件,该文件实际上是 TIFF 或 PNG 格式。查看文件的前几个字节并使用该签名来识别文件的格式,例如此处。如果是 JPEG,请使用 Calvin Hass 的 JPEGsnoop 等程序获取更多详细信息。 (没有私人关系,我只是一个快乐的用户。)如果它实际上是 TIFF,您可以通过 AsTiffTagViewer 由 Aware Systems 提供。
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.