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

11 comments:


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

    ReplyDelete
    Replies
    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

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

    ReplyDelete
  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

    ReplyDelete
  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

    ReplyDelete

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

    تنظيف خزانات

    ReplyDelete
  6. The Collection Marts is platform where you can view latest designs about home décor and bedding. We have large range in different categories with finest fabric in cotton and silk. You can view not only present trends but also view huge collection with reasonable price. The Collection Marts can provide fast service about delivery as well as customer support too. Our products are not only self-made but also, well connected with markets to ensure for possibility of available designs if client want to purchase. The Collection Marts customer support open 24/7 to guide their customers about material or product stuff. holiday sheet set , fluffy bed sets , chambray sheets , fancy bed sheets online , double bed duvet cover , vicky razai website , sofa cover with cushion cover , velvet bedsheet , razai covers , micro-cotton towels bed bath and beyond

    ReplyDelete
  7. Purdue Pharma is the Best place to Buy Oxycontin Online and to also buy other medicines online with overnight delivery. Buy Ambien Online and order medicines online without prescription with overnight delivery in the USA at a discounted price from best online pharmacy and best online medical store.

    buy ambien online, buy ambien 10mg online, buy ambien 5mg online, ambien, ambien 10mg, ambien 5mg.

    Buy Oxycontin Online

    Buy xanax Online

    Buy Adderall Online

    Buy Tramadol Online

    ReplyDelete