title: Convert Image into ByteArray
body: <p>I know there already are plenty of post about this, but every solution I have tried so far failed. What I want is to get a <code>Byte[]</code> from an <code>Image</code> object.</p>
  
  <p>What I have tried so far:</p>
  
  <ul>
  <li><code>using (MemoryStream ms = new MemoryStream()){/*...*/}</code> <strong>(GDI+ Exception)</strong></li>
  <li>Working on a copy of the <code>image</code> <strong>(ArgumentNullException (Encoder))</strong></li>
  <li>Follow the <a href="http://support.microsoft.com/kb/814675" rel="nofollow">solution from Microsoft</a> <strong>(ArgumentNullException (Encoder))</strong></li>
  <li>Use an <code>ImageConverter</code> <strong>(GDI+ Exception)</strong></li>
  </ul>
  
  <p>What I expect to have:</p>
  
  <pre><code>public static Byte[] BytesFromImage(Image img) {
  Byte[] imgFile;
  MemoryStream ms = new MemoryStream();
  img.Save(ms, img.RawFormat);
  imgfile = ms.ToArray();
  return imgFile;
  }
  </code></pre>
  
  <p>Everytime I get an error, it comes from <code>img.save(ms, img.RawFormat);</code>.</p>
  
  <p>Maybe it is just me, but all of the solution that I've followed on StackOverflow gave me the same results: a GDI+ Error with such a great explanation.</p>