title: How to find reason for Generic GDI+ error when saving an image?
body: <p>Having a code that works for ages when loading and storing images, I discovered that I have <em>one single image</em> that breaks this code:</p>
  <pre><code>const string i1Path = @&quot;c:\my\i1.jpg&quot;;
  const string i2Path = @&quot;c:\my\i2.jpg&quot;;
  
  var i = Image.FromFile(i1Path);
  i.Save(i2Path, ImageFormat.Jpeg);
  </code></pre>
  <p>The exception is:</p>
  <blockquote>
  <p>System.Runtime.InteropServices.ExternalException occurred</p>
  <p><strong>A generic error occurred in GDI+.</strong></p>
  <p>at System.Drawing.Image.Save(String filename, ImageCodecInfo encoder, EncoderParameters encoderParams)<br />
  at System.Drawing.Image.Save(String filename, ImageFormat format)<br />
  at ...</p>
  </blockquote>
  <p>As far as I can see, there is nothing special about the image. It is approx 250 pixels in size and can be opened in e.g. Windows Image Viewer or Paint.NET:</p>
  <p><img src="https://i.stack.imgur.com/qm3l3.jpg" alt="enter image description here" /></p>
  <p><em>(Since the image above, after being uploaded to Stack Overflow does not produce the error anymore, I've put <a href="https://www.magerquark.de/misc/i1.jpg" rel="noreferrer">the original image here</a>)</em></p>
  <p>What I discovered is that upon calling the <a href="https://docs.microsoft.com/en-us/dotnet/api/system.drawing.image.save?view=dotnet-plat-ext-3.1#System_Drawing_Image_Save_System_String_System_Drawing_Imaging_ImageFormat_" rel="noreferrer"><code>Save</code> method</a>, the destination image file is being created with zero bytes.</p>
  <p>I am really clueless on what causes the error.</p>
  <p><strong>My questions:</strong></p>
  <ul>
  <li>Can you think of any special thing that would hinder .NET from saving the image?</li>
  <li>Is there any way (beside panicing) to narrow down these kind of errors?</li>
  </ul>