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 sa开发者_JAVA技巧mpl 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.
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.
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.
精彩评论