Note that there are some explanatory texts on larger screens.

plurals
  1. POImage cropping and resizing ImageMagick vs GDI+ in C#
    primarykey
    data
    text
    <p>I have a web application where users can upload pictures to create their galleries. Years ago when I wrote the application I choose <a href="http://en.wikipedia.org/wiki/ImageMagick" rel="nofollow">ImageMagick</a>, and I did all my cropping and resizing with ImageMagick.</p> <p>Now that I am rewriting the application from scratch, <strong>I replaced ImageMagick with native <a href="http://en.wikipedia.org/wiki/Graphics_Device_Interface#Windows_XP" rel="nofollow">GDI+</a></strong> operations, but the more I learn around GDI+ the more I am scared I made the wrong choice.</p> <p>Everywhere I read that GDI+ is for the desktop and should not be used on a server application. I don't know the details, but I guess it's for the memory consumption, and indeed I can see <strong>GDI+ is using more memory</strong> to do the <strong>same operation</strong> (crop and resize) over the <strong>same image</strong> than ImageMagick (while to be honest <strong>GDI+ is faster</strong>).</p> <p>I believed GDI+, ImageMagick or any other library should be more or less the same for those basic operations, and I liked the idea of using native GDI+ believing whatever MS is shipping with <a href="http://en.wikipedia.org/wiki/.NET_Framework" rel="nofollow">.NET</a> should be at least OK.</p> <p>What is the right approach/tool to use?</p> <p>This is the code I use to crop:</p> <pre><code>internal Image Crop(Image image, Rectangle r) { Bitmap bmpCrop; using (Bitmap bmpImage = new Bitmap(image)) { bmpCrop = bmpImage.Clone(r, bmpImage.PixelFormat); bmpImage.Dispose(); } return (Image)(bmpCrop); } </code></pre> <p>This is the code I use to resize:</p> <pre><code>internal Image ResizeTo(Image sourceImage, int width, int height) { System.Drawing.Image newImage = new Bitmap(width, height); using (Graphics gr = Graphics.FromImage(newImage)) { gr.SmoothingMode = SmoothingMode.AntiAlias; gr.InterpolationMode = InterpolationMode.HighQualityBicubic; gr.PixelOffsetMode = PixelOffsetMode.HighQuality; gr.DrawImage(sourceImage, new Rectangle(0, 0, width, height)); gr.Dispose(); } return newImage; } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload