Page 1 of 1

Making tif file with jpeg compression

Posted: 2017-11-24T09:18:52-07:00
by zajic
Hi,

This may be a simple task, but I can't find a solution for it in Magick.NET
I have an image and I want to compress it with JPEG compression and add it into a TIF file. This is my code:

Code: Select all

MagickImage mgckImgTif = new MagickImage(new Bitmap(firstImageFromScanner));
mgckImgTif.CompressionMethod = CompressionMethod.JPEG;
mgckImgTif.Format = MagickFormat.Tif;
mgckImgTif.Write(convertedMs);
The file is created, but it is not compressed and is really large (which is why I want to compress it).
I've found that in ImageMagick you need to explicitly call the compress method, but I couldn't find it's equivalent in Magick.NET
Is there a way, to make it work?

Thanks in advance!

Re: Making tif file with jpeg compression

Posted: 2017-11-24T16:09:29-07:00
by dlemstra
Setting the CompressionMethod should let you use JPEG compression. What are you running on the command line?

Re: Making tif file with jpeg compression

Posted: 2017-12-01T09:45:03-07:00
by zajic
I am not using command line at all. The code you see is all I am doing.

Here is even simpler version of it:
(the input, in the sourcePath, is a jpeg file)

Code: Select all

MagickImage mgck = new MagickImage(sourcePath);
mgck.CompressionMethod = CompressionMethod.JPEG;
mgck.Write(outputPath + fileName + ".tif");
But not even this works! It creates a tif file, but with no compression.
If I set the compression method to Group4, it works just fine, but not with JPEG.

So I guess there might be some bug with JPEG and TIF, but maybe I'm just missing something.

Re: Making tif file with jpeg compression

Posted: 2017-12-02T11:26:54-07:00
by dlemstra
You should use `mgck.Settings.CompressionMethod` instead. The `mgck.CompressionMethod` should be used for getting the compression when an image is being read. I will take a look at the code in ImageMagick and make sure we don't use the `mgck.CompressionMethod` inside the image encoders. I will also make sure that `mgck.CompressionMethod` will become read only in the next release to avoid the confusion.

p.s. Don't forget to put `mgck` inside a using block.