Making tif file with jpeg compression

Magick.NET is an object-oriented C# interface to ImageMagick. Use this forum to discuss, make suggestions about, or report bugs concerning Magick.NET
Post Reply
zajic
Posts: 4
Joined: 2017-09-26T10:17:00-07:00
Authentication code: 1151

Making tif file with jpeg compression

Post 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!
User avatar
dlemstra
Posts: 1570
Joined: 2013-05-04T15:28:54-07:00
Authentication code: 6789
Contact:

Re: Making tif file with jpeg compression

Post by dlemstra »

Setting the CompressionMethod should let you use JPEG compression. What are you running on the command line?
.NET + ImageMagick = Magick.NET https://github.com/dlemstra/Magick.NET, @MagickNET, Donate
zajic
Posts: 4
Joined: 2017-09-26T10:17:00-07:00
Authentication code: 1151

Re: Making tif file with jpeg compression

Post 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.
User avatar
dlemstra
Posts: 1570
Joined: 2013-05-04T15:28:54-07:00
Authentication code: 6789
Contact:

Re: Making tif file with jpeg compression

Post 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.
.NET + ImageMagick = Magick.NET https://github.com/dlemstra/Magick.NET, @MagickNET, Donate
Post Reply