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

3 comments:

  1. Buy t shirt for men online online from Dshred at best prices delivered at your doorstep. Get free shipping

    ReplyDelete
  2. When we share a image on social media and upload on website, We need image cropping, You deliver the best technique for image cropping. Thank you for sharing with us. Further, The professional kitchen remodeling services in Clovis ca deliver the outstanding work.

    ReplyDelete