how to use imageMagick with C#

后端 未结 3 1668
闹比i
闹比i 2020-12-15 12:36

Could you explain how I can use ImageMagick with C# . I am trying to convert PDF to pages into images.

I want to run imageMagick command \"convert -density 300 $inp

相关标签:
3条回答
  • 2020-12-15 13:00
    string arguments = string.Format(@"-density 300 {0}.pdf {1}.png", intputFileName, outputFileName");
    var startInfo = new ProcessStartInfo {
        Arguments = arguments,
        Filename = @"C:\path\to\imagick\convert.exe"
    };
    Process.Start(startInfo).WaitForExit();
    

    References:

    • ProcessStartInfo
    • Process
    0 讨论(0)
  • 2020-12-15 13:17

    Magic.Net is a C# port for popular library ImageMagick. Install Magick.Net using Nuget package from url https://www.nuget.org/packages/Magick.NET-Q16-AnyCPU/ . Note that there are many versions of Magick.Net so select as per your need. This way you can use C#. See code below

    Note it will append images vertically. Similarly you can append horizontally.

    using ImageMagick;
    
    string inputPdf= @"C:\my docs\input.pdf";
    string outputPng= @"C:\my docs\output.png";
    
    using (MagickImageCollection images = new MagickImageCollection())
    {
        images.Read(inputPdf);
        using (IMagickImage vertical = images.AppendVertically())
            {
                vertical.Format = MagickFormat.Png;
                vertical.Density = new Density(300);  
                vertical.Write(outputPng);
            }
    }
    
    0 讨论(0)
  • 2020-12-15 13:21

    It's better to use Magick.NET, no need to install ImageMagick on clients: http://magick.codeplex.com/

    0 讨论(0)
提交回复
热议问题