Page 1 of 1

Compression not working on TIFF, through jmagick (on Android)?

Posted: 2015-03-12T10:19:57-07:00
by timewasted
Hi everyone. I'm new to jmagick and imagemagick, so please bare with me
here.

Short explanation of question/problem: How do I get the compression to
actually take when creating a tiff file?

Longer explanation: I'm doing some image manipulation on Android and have
jmagick working. I'm taking jpg image captures and adjusting the size,
grayscaling and then setting it to 2 colors and 1 bit per pixel. All of
this works fine and I end up with a file that is about 500K per image. I'm
allowing users to capture multiple images and then combine them into a
mutli-page document.

When I first get the image I do this:

Code: Select all

                String path = params[0];
                ImageInfo imageInfo = new ImageInfo(path);
                MagickImage mImage = new MagickImage(imageInfo);
                if(mImage.getWidth() > mImage.getHeight()) mImage =
mImage.rotateImage(90);
                mImage = mImage.scaleImage(1728, 1728 * mImage.getHeight()
/ mImage.getWidth());

                QuantizeInfo qInfo = new QuantizeInfo();
                qInfo.setNumberColors(2);
                qInfo.setTreeDepth(0);
                qInfo.setColorspace(ColorspaceType.GRAYColorspace);
                mImage.quantizeImage(qInfo); // This is what takes so much
time.
                mImage.writeImage(imageInfo);

Later, when combining the images, I do this:

Code: Select all

           String outPath =
Environment.getExternalStorageDirectory().getAbsolutePath() +
                    "/Android/data/" +
getApplicationContext().getPackageName() + "/files/tmp.tiff";
            ArrayList<String> paths = new ArrayList<>();
            int count = gridViewAdapter.getCount();
            MagickImage[] images = new MagickImage[count];

            for(int i = 0; i < count; i++) {

paths.add(((ThumbnailViewItem)gridViewAdapter.getItem(i)).path);
                Log.d(Util.getTag(getApplicationContext()), "Path: " +
paths.get(i));
                ImageInfo imageInfo = new ImageInfo(paths.get(i));
                images[i] = new MagickImage(imageInfo);
            }

            MagickImage combinedImage = new MagickImage(images);
            ImageInfo newInfo = new ImageInfo(outPath);
            newInfo.setFileName(outPath);
            combinedImage.setMagick("TIFF");
            combinedImage.setDepth(1);
            combinedImage.setCompression(CompressionType.Group4Compression);
            combinedImage.setUnits(ResolutionType.PixelsPerInchResolution);
            combinedImage.setXResolution(200.00);
            combinedImage.setYResolution(200.00);
            combinedImage.writeImage(newInfo);

            return combinedImage.imagesToBlob(newInfo);
The problem is that even though I have set compression and I do get a
multipage tiff, the resulting file is still large and doesn't show as
having compression set. This is the result of tiffinfo on the file:

Code: Select all

 tiffinfo 0051e9a140b50bcd51ecc8b7fcce2b_23_O_0014645_1.tiff
TIFF Directory at offset 0x79808 (497672)
  Image Width: 1728 Image Length: 2304
  Resolution: 200, 200 pixels/inch
  Bits/Sample: 1
  Compression Scheme: None
  Photometric Interpretation: min-is-black
  FillOrder: msb-to-lsb
  Orientation: row 0 top, col 0 lhs
  Samples/Pixel: 1
  Rows/Strip: 37
  Planar Configuration: single image plane
  Page Number: 0-1
  DocumentName:
Any thoughts?

Mark