title: Image.Save() throws exception "Value cannot be null./r/nParameter name: encoder"
body: <p>I am getting "Value cannot be null.\r\nParameter name: encoder" error while saving a Bitmap image using RawFormat.
  Sample code:</p>
  
  <pre><code>class Program
  {
      static void Main(string[] args)
      {
          try
          {
              var image = new System.Drawing.Bitmap(500, 400);
              var stream = new MemoryStream();
              image.Save(stream, image.RawFormat);
          }
          catch (Exception exp)
          {
              Console.WriteLine(exp.ToString());
          }
      }
  }
  </code></pre>
  
  <p>The RawFormat doesn't exist in the existing list of ImageEncoders as below code returns null.</p>
  
  <p><code>var imageCodecInfo = ImageCodecInfo.GetImageEncoders().FirstOrDefault(codec =&gt; codec.FormatID == image.RawFormat.Guid);</code></p>
  
  <p>Note: The image could be any type(JPEG, BMP, PNG) etc. Image.Save() should work on image.RawFormat.
  RawFormat is not Bitmap type. If I Change image.RawFormat to ImageFormat.Bmp, the save operation succeeds.</p>
  
  <p>Referred below links but found nothing for making it independent of image type.</p>
  
  <p><a href="https://stackoverflow.com/questions/9073619/image-save-crashing-value-cannot-be-null-r-nparameter-name-encoder">Image.Save crashing: {&quot;Value cannot be null.\r\nParameter name: encoder&quot;}</a>
  <a href="https://stackoverflow.com/questions/4172112/why-is-image-savestream-imageformat-throwing-an-exception">Why is Image.Save(Stream, ImageFormat) throwing an exception?</a></p>
  
  <p>Any suggestions are welcome.</p>