find a location for property in a new city

Wednesday, 16 February 2011

OutOfMemoryException when cropping image

When cropping an image using System.Drawing.Bitmap.Clone(Rectangle rect, PixelFormat format) I was receiving an OutOfMemoryException complaining that I was "Out of memory" when trying to crop an Image bitmap in C#.

So I started to assume that I was out of memory as in physical storage on my machine as you might expect. Turns out that that is not in fact the case as you would surely assume...

What's wrong with this clone?!

Well it turns out that the cropping was happening on an image (1 pixel) smaller than the desired cropping size. So I changed my logic about a bit to essentially make sure that the source image is at least the size of the desired crop size. And now the OutOfMemoryException on my Image processing code is working just fine.

Follow britishdev on Twitter


  1. Thanks for posting this useful content, Good to know about new things here, Let me share this, . Hadoop training in pune

    1. Great Article Image Processing Projects Deep Learning Projects for Final Year JavaScript Training in Chennai JavaScript Training in Chennai The Angular Training covers a wide range of topics including Components, Angular Directives, Angular Services, Pipes, security fundamentals, Routing, and Angular programmability. The new Angular TRaining will lay the foundation you need to specialise in Single Page Application developer. Angular Training Project Centers in Chennai

  2. Very helpful post.Thanks for your great information! Keep sharing.
    erp in chennai | erp software providers in chennai

  3. Nice Blog.Thank you for Sharing. We are leading erp software software solution providers in chennai. For more details call +91 9677025199. erp software in chennai | erp providers in chennai | online events registration

  4. The website is looking bit flashy and it catches the visitors eyes. A design is pretty simple and a good user-friendly interface.

    Programmierung in Lüdenscheid


  5. الرائد افضل شركة تنظيف و غسيل خزانات بالمدينة المنورة تنظيف خزانات بالمدينة المنورة وتقوم اياب تقيمها بالاشعه الفوق البنفسجية

    تنظيف خزانات