如何在Magick.NET中创建黑白图像 [英] How to create black and white images in Magick.NET
本文介绍了如何在Magick.NET中创建黑白图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想通过黑白图像创建TIF,PNG,JPG和BMP之类的黑白图像 https://magick.codeplex.com .
I would like create TIF, PNG, JPG and BMP like black and white images via https://magick.codeplex.com.
如果我喜欢我的代码,我发现我只能生成TIF黑色,为什么生成图像,而不能生成其他类型的图像.
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.
任何提示如何解决?
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);
}
推荐答案
我在这里找到了答案 https://magick.codeplex.com/discussions/637181
using (MagickImage image = new MagickImage(pathToTiffFile))
{
image.Threshold(60); // 60 is OK
image.Depth = 1;
image.Write(pathToOutputFile);
}
这篇关于如何在Magick.NET中创建黑白图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文