【问题标题】:How to create black and white images in Magick.NET如何在 Magick.NET 中创建黑白图像
【发布时间】:2016-06-27 18:36:37
【问题描述】:

我想通过以下方式创建像黑白图像一样的 TIF、PNG、JPG 和 BMP https://magick.codeplex.com.

我发现如果我喜欢我的代码,我只能生成 TIF 黑色以及为什么图像而不是其他类型的图像。

有什么解决办法吗?

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);
}

【问题讨论】:

  • 是否有任何文档可供您查看是否有其他图像类型的示例..?除了在那里粘贴代码之外,您还尝试过什么..?你检查过谷歌搜索..? magick.codeplex.com/documentation有一个部分用于创建动画GIF和其他图像类型
  • newFileName 的值是多少,是否包含扩展名?看起来您没有根据输出格式更改它。
  • @dlemstra 你好!是的,它对所有情况都有正确的扩展。我能够找到解决这个问题的方法。谢谢!

标签: c# .net imagemagick magick.net


【解决方案1】:

我在这里找到了答案https://magick.codeplex.com/discussions/637181

using (MagickImage image = new MagickImage(pathToTiffFile))
{
    image.Threshold(60); // 60 is OK 
    image.Depth = 1;
    image.Write(pathToOutputFile);
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2014-12-24
    • 2011-03-08
    • 2013-08-30
    • 1970-01-01
    • 2019-12-16
    • 1970-01-01
    • 2020-01-21
    • 2012-05-14
    相关资源
    最近更新 更多