title: Get ImageFormat from System.Drawing.Image.RawFormat
body: <p>This code fails when trying to call <code>Image.Save(MemoryStream, ImageFormat)</code>. </p>
  
  <p>I get the exception:</p>
  
  <blockquote>
    <p>a Value cannot be null.Parameter name: encoder"</p>
  </blockquote>
  
  <pre class="lang-c# prettyprint-override"><code>ImageFormat format = generatedImage.RawFormat as ImageFormat;
  image.ImageData = generatedImage.Save(format);
  </code></pre>
  
  <p>It works if I pass in an <code>ImageFormat</code> object directly e.g. <code>ImageFormat.Jpeg</code>.</p>
  
  <p>What is the best way of converting the <code>rawformat</code> to <code>ImageFormat</code> (ideally without a switch statement or lots of if statements)</p>
  
  <p>Thanks
  Ben</p>