Quantcast
Channel: magick Discussions Rss Feed
Viewing all articles
Browse latest Browse all 3693

New Post: Magick.NET and Mono

$
0
0
That's fair enough, having it all as one library makes it easy to use :)

For what it's worth, here's the solution I came up with for resizing images using GraphicsMagick, which works on both MS.NET and Mono. I'm using GraphicsMagick to work around the horrible quality of resized images in Mono. Mono's GDI+/System.Drawing implementation uses Cairo which just does a bilinear resize with no nicer interpolation options.
/// <summary>
/// Generates a thumbnail for the specified image, using ImageMagick or GraphicsMagick
/// </summary>
/// <param name="sourceImg">Image to generate thumbnail for</param>
/// <param name="width">Width of the thumbnail</param>
/// <param name="height">Height of the thumbnail</param>
/// <returns>Thumbnail image</returns>
public static Bitmap GenerateMagickThumbnail(this Image sourceImg, int width, int height)
{
    // Create new GraphicsMagick process for thumbnail generation
    var process = new Process
    {
        StartInfo = new ProcessStartInfo
        {
            FileName = "gm",
            Arguments = string.Format("convert - -filter sinc -size {0}x{1} -resize {0}x{1} -", width, height),
            RedirectStandardInput = true,
            RedirectStandardOutput = true,
            RedirectStandardError = true,
            UseShellExecute = false,
            CreateNoWindow = true,
        }
    };

    process.Start();

    // Write source image to input stream of GraphicsMagick
    sourceImg.Save(process.StandardInput.BaseStream, ImageFormat.Png);
    process.StandardInput.Flush();
    process.StandardInput.Close();

    try
    {
        var thumb = new Bitmap(process.StandardOutput.BaseStream);
        return thumb;
    }
    catch (Exception ex)
    {
        var errors = process.StandardError.ReadToEnd();
        throw new Exception(string.Format("Error invoking GraphicsMagick: {0}\nOriginal exception: {1}", errors, ex));
    }
    finally
    {
        process.Dispose();
    }
}

Viewing all articles
Browse latest Browse all 3693

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>