title: System.Drawing / GDI+ Error while producing graphics for web on the fly
body: <p>I am building a .NET based e-commerce site for a business that makes novelty signs that are created by the customer in real time on the site. The idea is a bit different than some sites where you have to do all the design work yourself - on this site there are basically signs grouped together into themes with predetermined "text areas" where the customer inputs their unique text. I then build a graphic on the fly on the SERVER side using System.Drawing / GDI+. I've found that after producing around 9,000 graphics (the number is probably irrelevant, it's probably tied to another operational action), i get a vague GDI+ error and the entire website resets. I'm wondering if there's a better graphics routine I should be using, as I've gone through my code, released and cleaned up objects, cached images so the same image isn't processed over and over, and still get the error. This happens whether I produce the images one by one (say over several days) or as a big batch (which will be used, on occasion, for bulk uploads to other online stores).</p>
  
  <p>The error I see in the event log </p>
  
  <blockquote>
    <p>Faulting application w3wp.exe, version 7.0.6002.18005, time stamp 0x49e023cf, faulting module gdiplus.dll, version 5.2.6002.18813, time stamp 0x515ba857, exception code 0xc0000005, fault offset 0x00104be6, process id 0x1018, application start time 0x01ce82423201ac62.</p>
  </blockquote>
  
  <p>Sure feels like a memory issue, but I can't find it.</p>
  
  <p>My code incorporates quite a few components, such as:</p>
  
  <ul>
  <li>Loading base image from disk and resizing to a "working" size for manipulation</li>
  <li>Adding 1-X pieces of custom text (X is determined by the product)</li>
  <li>Smooth the text and scale it proportionally.</li>
  <li>Each of these pieces of custom text can have a different font, color, etc.</li>
  <li>Each of these pieces of text can have a drop shadow (same text, scooted over)</li>
  <li>Overlay the image with a semi-transparent graphic to "weather" or "wood-grain" the entire image, AFTER the text is added.</li>
  </ul>
  
  <p>All of this is easily accomplished using some basic loops and GDI+ drawing techniques. I also considered doing it on the client side using JavaScript, but because of the all the unique options that can be set PER product and the use of server-side, specially licensed fonts, this would get crazy complicated.</p>
  
  <p>I don't see any big memory leak or even a freeing of memory when the site resets.</p>
  
  <p>So what I'm really looking for is opinions as to whether I should go to a different server-side drawing routine. I can't really copy over a good sampling of my code, as the drawing routine alone is over 500 lines of code, but it uses a lot of DrawString, SmoothingMode, InterpolationMode, PixelOffsetMode, SetResolution etc. methods and properties.</p>
  
  <p>You're welcome to take a look at the site in action as well - <a href="http://dev.signshop.c2itconsulting.net" rel="nofollow">http://dev.signshop.c2itconsulting.net</a></p>