title: OutOfMemoryException: Out of memory - System.Drawing.Graphics.FromImage
body: <p>I get Out of Memory exception when using System.Drawing.Graphics.FromImage (using latest versions of .NET software on Windows 2012 server), <strong>ONLY on a very few specific image files</strong>.  Most of the time the code works fine.</p>
  
  <p>Typical answers to above issue indicate that certain resources are not being released.</p>
  
  <p><strong>Please consider the following before answering:-</strong></p>
  
  <ul>
  <li>This specific image is 34KB in size, is a .JPG image. Server is idle and has over 32GB RAM.</li>
  <li>If I look at properties of
  this jpg file, using windows explorer, by right-clicking on file, Windows says: <strong>96 dpi and 32 bit depth</strong>. </li>
  <li>BUT, if I open this jpg file using any graphics program (e.g. photoshop), the file properties show as:  <strong>72 dpi and 24 bit depth</strong>.   </li>
  <li>So, there is a <strong>mis-match between what I think file header properties
  say and what the file actually contains</strong>. </li>
  <li>Further, if I open the jpg
  file using a graphics program and <strong>just re-save without changing
  anything</strong>, the file properties in windows explorer now match/read correct
  (72 dpi and 24 bit depth); and the <strong>file is processed by
  System.Drawing.Graphics correctly, without throwing exception</strong>.</li>
  </ul>
  
  <p>Due to my limited knowledge of the subject, I don't know <strong>if the file header of an image file can contain different data from actual file contents</strong>.</p>
  
  <p><strong>Questions:</strong></p>
  
  <p>How can I fix this problem?  Or how can I tell System.Drawing.Graphics to ignore file header data and just look at actual image file contents?  (as all graphics programs such as photoshop appear to do).</p>
  
  <p>Thanks!</p>