1

I would like create TIF, PNG, JPG and BMP like black and white images via https://magick.codeplex.com.

What I found if I do like in my code I can generate only TIF black and why images but not images of other types.

Any clue how to fix it?

MagickReadSettings readSettings = new MagickReadSettings()
{
    UseMonochrome = true                    
};

using (MagickImage image = new MagickImage(fileInfo.FullName, readSettings))
{
    image.AddProfile(ColorProfile.SRGB);

    if (Properties.Settings.Default.ImageFileExtentionToConvert.ToLower().Contains("tif"))
    {
        image.CompressionMethod = CompressionMethod.Group4;
        image.ColorSpace = ColorSpace.Gray;

        image.Format = MagickFormat.Tif;
    }
    else if (Properties.Settings.Default.ImageFileExtentionToConvert.ToLower().Contains("png"))
    {
        // image.ColorSpace = ColorSpace.Gray;
        image.Settings.SetDefine(MagickFormat.Png, "compression-strategy", "0");
        image.Settings.SetDefine(MagickFormat.Png, "compression-filter", "0");

        image.Format = MagickFormat.Png;
    }
    else if (Properties.Settings.Default.ImageFileExtentionToConvert.ToLower().Contains("jpg"))
    {
        image.Settings.SetDefine(MagickFormat.Jpg, "compression-strategy", "0");
        image.Settings.SetDefine(MagickFormat.Jpg, "compression-filter", "0");

        image.Format = MagickFormat.Jpg;
    }
    else  
    {
        image.CompressionMethod = CompressionMethod.NoCompression;

        image.Format = MagickFormat.Bmp;
    }

    image.Write(newFileName);
}
Vadim Ovchinnikov
  • 13,327
  • 5
  • 62
  • 90
NoWar
  • 36,338
  • 80
  • 323
  • 498
  • is there any documentation that you can go to and see if there are examples of other image types ..? what have you tried besides pasting the code there..? have you checked Google searches..? https://magick.codeplex.com/documentation there is a section for creating Animated GIF and other Image types – MethodMan Jun 27 '16 at 18:45
  • What is the value of newFileName, does it include an extension? It looks like you are not changing it based on the output format. – dlemstra Jun 27 '16 at 18:53
  • @dlemstra Hi! Yes it has correct extension for all cases.I was able to find a solution for this issue. Thank you! – NoWar Jun 28 '16 at 12:36

1 Answers1

3

I found the answer here https://magick.codeplex.com/discussions/637181

using (MagickImage image = new MagickImage(pathToTiffFile))
{
    image.Threshold(60); // 60 is OK 
    image.Depth = 1;
    image.Write(pathToOutputFile);
}
NoWar
  • 36,338
  • 80
  • 323
  • 498