title: System.Drawing.Image.Save throws ExternalException: A generic error occurred in GDI
body: <p>I have function which takes a bitmap, copies part of it and saves it as 8bpp tiff. Filename of the result image is unique and file doesn't exist, program has permission to write to the target folder.</p>
  
  <pre><code>void CropImage(Bitmap map) {
          Bitmap croped = new Bitmap(200, 50);
  
          using (Graphics g = Graphics.FromImage(croped)) {
              g.DrawImage(map, new Rectangle(0, 0, 200, 50), ...);
          }
  
          var encoderParams = new EncoderParameters(2);
          encoderParams.Param[0] = new EncoderParameter(System.Drawing.Imaging.Encoder.ColorDepth, 8L);
          encoderParams.Param[1] = new EncoderParameter(System.Drawing.Imaging.Encoder.Compression, (long)EncoderValue.CompressionNone);
  
          croped.Save(filename, tiffEncoder, encoderParams);
          croped.Dispose();
      }
  </code></pre>
  
  <p>Weird thing is that this funcion works well on some computers (Win 7) and throws System.Runtime.InteropServices.ExternalException: A generic error occurred in GDI exception on other computers (mostly Win XP).</p>
  
  <p>All computers have the .NET 3.5 SP1 runtime installed.</p>
  
  <p>If I use <code>croped.Save(filename, ImageFormat.Tiff);</code> instead <code>croped.Save(filename, tiffEncoder, encoderParams);</code> than it works on all computers, but I need to save Tiff in 8bpp format.</p>
  
  <p>Do you have any ideas, where the problem could be?</p>
  
  <p>Thanks, Lukas</p>