Question about compression type
Can you please tell me why the LZWcompression is generating images less compress that CCITTFAX4, since we need the best compression without lossing the quality.
Regards,
CCITTFAX3 and 4 support only binary images(black and white without alpha, color and grayscale). So when you use CCITTFAX compression - image transformed to binary image. LZW just compress colorfull image and save it. when you use LZW every pixel encodes with 24 bytes (Alpha Red Green Blue, 8bits per chanel) when you use CCITTFAX every pixel encodes with 1 bit(1 or 0) LZW is recommended compression scheme for TIFF images
Thanks for the quick response, well actually we are converting images take with and android camera, then we apply a binary filter, and then we convert/compress to tiff images so I'm looking the best to reduce the space since we need to send through web service api.
So if you using binary filter and has image with only black and white pixels - use CCITTFAX3 or 4. it should get minimum size.
Awesome Thanks!!!
Hi @Beyka and @eoherrer,
I would like to get images in 3 format greyscale(100 DPI) jpeg, Black&White (200 DPI) and Colour (200 DPI) tiff.
Can I use this library to get those images ?
If yes, then please provide me the document/guide to follow.
Thanks.
@kirantpatil
//For greyscale you should use bitmap in greyscale. Library couldn't make greyscale image from colorfull image
Bitmap bitmap = BitmapFactory.decodeFile("/sdcard/Download/test_greyscale.png");
File gr100f = new File("/sdcard/Download/greyscale100.tif");
TiffSaver.SaveOptions gr100 = new TiffSaver.SaveOptions();
gr100.compressionScheme = CompressionScheme.JPEG;
gr100.resUnit = ResolutionUnit.INCH;
gr100.xResolution = 100;
gr100.yResolution = 100;
TiffSaver.saveBitmap(gr100f, bitmap, gr100);
//For black and white you could use CCITT compression schemes - library will convert image to b&w format
//If you want any other format - you should convert your bitmap to black and white and than save it
Bitmap bitmap2 = BitmapFactory.decodeFile("/sdcard/Download/test.png");
File bw200f = new File("/sdcard/Download/black_white_200.tif");
TiffSaver.SaveOptions bw200 = new TiffSaver.SaveOptions();
bw200.compressionScheme = CompressionScheme.CCITTFAX4;
bw200.resUnit = ResolutionUnit.INCH;
bw200.xResolution = 200;
bw200.yResolution = 200;
TiffSaver.saveBitmap(bw200f, bitmap2, bw200);
//For colorfull format you could use any compression schemes except CCITT
File c200f = new File("/sdcard/Download/black_white_200.tif");
TiffSaver.SaveOptions c200 = new TiffSaver.SaveOptions();
c200.compressionScheme = CompressionScheme.JPEG;
c200.resUnit = ResolutionUnit.INCH;
c200.xResolution = 200;
c200.yResolution = 200;
TiffSaver.saveBitmap(c200f, bitmap2, c200);
Any way DPI is just tiff tags and if application that you use to open tiff files to uses this tags - it will not work. Also any color transformations except "any to b&w" you should do yourself.
@Beyka, Thanks a lot, that clarified lot of confusions I had.
Hi @Beyka,
I used below code.
Bitmap bitmap = BitmapFactory.decodeFile("/sdcard/Download/test_greyscale.png");
File gr100f = new File("/sdcard/Download/greyscale100.tif");
TiffSaver.SaveOptions gr100 = new TiffSaver.SaveOptions();
gr100.compressionScheme = CompressionScheme.JPEG;
gr100.resUnit = ResolutionUnit.INCH;
gr100.xResolution = 100;
gr100.yResolution = 100;
TiffSaver.saveBitmap(gr100f, bitmap, gr100);
I passed the 24 bit depth grayscale image and the above code results in 32 bit depth grayscale image.
How can I change the image bit depth to 8 for grayscale ?
Is that the right way to get clear grayscale image ?
Please guide me.
Below am attaching 32-bit and 8-bit images
Below image with 8 bit is much clear than the 32 bit which we processed.


@kirantpatil Sorry for long answer. Library not provide dirrect way to change bit depth. CCITTFAX4, CCITTFAX3 and CCITTRLE have 1 bit per component and 1 component per pixel JPEG has 8 bit per component and 3 component per pixel. So jpeg has 24 bit per pixel Any pther compression schemes have 8 bit per component and 4 component per pixel = 32bpp.
Also there are no any built-in converter except any to black and white.
One more: If you use TiffSaver - you have bitmap that converts to tiff. android bitmap by default has 32bpp but not 8. Maybe you should use TiffConverter class. It could do direct convertation from jpg/png to tiff and vise versa. Also if you original image is to big (if you should use inSampleSize option for BitmapFactory when read bitmap) you will lose data while save tiff if you use tiff saver. Tiff converter could handle this problem.
@Beyka,
I appreciate your detail answer. Your answer absolutely clear crystal for understanding deeper concept.
I used TiffConverter and passed jpeg image as tiff image(I know this is wrong) to convert again as jpeg.
The jpeg image is grayscale with 8 bit depth.
The converted image is not setting the X and Y resolution to 100 but 96 and the bit depth is 24 now.
Any help would be great.
Thanks.
I am using TiffConverter to convert to tiff but it is converting bitmap to some 8-byte TIFF which is not openable. and also it is returning false.Help me