将Magick.NET与C#结合使用 [英] Using Magick.NET with C#
问题描述
我正在尝试使用C#中的Magick.NET实现功能.
I am trying to implement a functionality using Magick.NET in C#.
以前我使用的是:-
// 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的问题.....现在,我想使用将在代码中使用的东西,而不必引用服务器上的可执行文件:-
I want to move away from having to store convert.exe on the server.....Now I want to use something that will be in code and doesn't need to reference an executable file on the server:-
// Pseudo-code:-
MagickImage img = new MagicImage();
Image.Add(svg);
Image.Format = MagickFormat.png;
Image.Scale = 60%;
但是我找不到足够的文档来实现以前使用的相同功能.有合适的文件资料吗?我已经在Google上搜索了很多,但没有成功.
But I cannot find enough documentation to implement the same functionality that I was using before. Is there a place with appropriate documentations? I have googled quite a bit, without success.
推荐答案
There are some examples of how to use Magick.NET available here.
有关如何将一个图像转换为另一图像的示例,请参见此处.但没有比例为60%
的示例.
An example of how to convert one image to another image can be found here. But there is no example for -scale 60%
.
大多数命令行选项在MagickImage类中具有相同的名称.您的命令 convert input.svg -scale 60%output.png
转换为:
Most options from the command line have the same name in the MagickImage class. Your command convert input.svg -scale 60% output.png
translates to this:
using (MagickImage image = new MagickImage("input.svg"))
{
image.Scale(new Percentage(60));
image.Write("output.png");
}
这篇关于将Magick.NET与C#结合使用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!