在 C# 中使用 Magick.NET

Using Magick.NET with C#

我正在尝试在 C# 中使用 Magick.NET 实现功能。

之前我使用的是:-

// Convert to a png.
Process p = new Process();

p.StartInfo.FileName = @"C:\Program Files\ImageMagick-6.2.8-Q16\convert.exe";
p.StartInfo.Arguments = "-scale 60% \"" + svg + "\" \"" + png + "\"";
p.StartInfo.CreateNoWindow = true;

p.Start();

p.WaitForExit();

TransmitFile(context, png);

我不想在服务器上存储 convert.exe.....现在我想使用代码中的东西,不需要引用服务器上的可执行文件服务器:-

// Pseudo-code:-
MagickImage img = new MagicImage();
Image.Add(svg);
Image.Format = MagickFormat.png;
Image.Scale = 60%;

但是我找不到足够的文档来实现我以前使用的相同功能。有合适的文件的地方吗?我用谷歌搜索了很多,但没有成功。

有一些如何使用 Magick.NET 的示例 here

可以找到如何将一张图像转换为另一张图像的示例 here。但是没有-scale 60%的例子。

命令行中的大多数选项在 MagickImage 中具有相同的名称class。您的命令 convert input.svg -scale 60% output.png 转换为:

using (MagickImage image = new MagickImage("input.svg"))
{
  image.Scale(new Percentage(60));
  image.Write("output.png");
}