Philo
Philo

Reputation: 1989

Using Magick.NET with C#

I am trying to implement a functionality using Magick.NET in C#.

Previously I was using:-

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

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%;

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.

Upvotes: 5

Views: 33302

Answers (1)

dlemstra
dlemstra

Reputation: 8143

There are some examples of how to use Magick.NET available here.

An example of how to convert one image to another image can be found here. But there is no example for -scale 60%.

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

Upvotes: 8

Related Questions