Search code examples
c#imagemagickimagemagick.net

Controlling image setting in code using ImageMagick.NET (code equivalent to command line -define)


I'm using ImageMagick.Net to write an image. I'm trying to control some settings in the output image. I can't figure out how to modify these settings from code, although they are available in ImageMagick command line (ImageMagick defines).

I'm specifically interested in modifying the "predictor" setting which is by default 3 when the image is compressed using the "Deflate" method.

Sample code:

        var collection = new MagickImageCollection(args[0]);
        IWriteDefines tiffWriteDefines= new TiffWriteDefines()
        {
            PreserveCompression = true
        };
        collection.Write(@"d:\outImage.tiff", tiffWriteDefines);

These settings are controlled from command line by specifying the

Magick image.tif -define tiff:predictor=1


Solution

  • After some work I found the answer: to modify this setting you should go over each of the images in the collection and:

    foreach (var image in imageCollection)
    {
        image.Settings.SetDefine(MagickFormat.Tiff, "predictor", "1");
    }
    

    this solved the problem for me.