我有一个TIFF,其中一个剪切路径存储在8BimProfile中。现在我想沿裁剪路径裁剪此图像。
我尝试了什么
我的第一种方法是使用MagickImage Clip()方法,它似乎什么都不做:
using (var image = new MagickImage(pathOfFileToClip))
{
image.Clip();
image.Write(targetPath);
}
我目前使用的解决方法调用ImageMagick convert.exe工具:
var wrappedFilePath = "\"" + pathOfFileToClip + "\"";
var arguments = wrappedFilePath + " -alpha transparent -clip -alpha opaque -strip " + wrappedFilePath;
var process = new System.Diagnostics.Process();
var startInfo = new System.Diagnostics.ProcessStartInfo
{
WindowStyle = System.Diagnostics.ProcessWindowStyle.Hidden,
FileName = @"C:\Program Files\ImageMagick-6.9.3-Q16\convert.exe",
Arguments = arguments
};
process.StartInfo = startInfo;
process.Start();
这很好用,并按照我想要的方式裁剪图像。但是如何在没有EXE的情况下让它工作呢?
只是采用这样的命令行参数也不起作用:
using (var image = new MagickImage(pathOfFileToClip))
{
image.AlphaColor = new MagickColor(Color.Transparent);
image.Clip();
image.AlphaColor = new MagickColor(Color.Black);
image.Strip();
image.Write(targetPath);
}
对工作解决方案的任何建议或链接表示赞赏。
答案 0 :(得分:2)
因此,当应用Alpha选项时,我使用了错误的方法:
using (var image = new MagickImage(pathOfFileToClip))
{
image.Alpha(AlphaOption.Transparent);
image.Clip();
image.Alpha(AlphaOption.Opaque);
image.Strip();
image.Write(targetPath);
}
我希望这仍然有助于任何尝试这种方法的人。