title: Convert BitmapImage to byte[]
body: <p>I have problem with converting BitmapImage to byte[]. I tried a lot of solutions and nothing works, every time i get different errors. </p>
  
  <p>For example i found nice solutions but it also doesn't work. What's wrong with it?</p>
  
  <p>I'm using Windows Phone 8.1.</p>
  
  <pre><code>public static byte[] ImageToBytes(BitmapImage img)
  {
      using (MemoryStream ms = new MemoryStream())
      {
          WriteableBitmap btmMap = new WriteableBitmap(img);
          System.Windows.Media.Imaging.Extensions.SaveJpeg(btmMap, ms, img.PixelWidth, img.PixelHeight, 0, 100);
          img = null;
          return ms.ToArray();
      }
  }
  </code></pre>
  
  <p>this was taken from here:  <a href="https://stackoverflow.com/questions/22241480/convert-bitmap-image-to-byte-array-windows-phone-8">Convert Bitmap Image to byte array (Windows phone 8)</a></p>
  
  <blockquote>
    <p>There is no argument given that corresponds to the required formal
    parameter 'pixelHeight' of 'WriteableBitmap.WriteableBitmap(int, int)'</p>
    
    <p>The type or namespace name 'Extensions' does not exist in the
    namespace 'System.Windows.Media.Imaging' (are you missing an assembly
    reference?)</p>
  </blockquote>
  
  <p>or if somebody has got another idea how to convert it, please post it. Thanks a lot for any help!</p>
  
  <p>I also tried this: <a href="https://stackoverflow.com/questions/6597676/bitmapimage-to-byte">BitmapImage to byte[]</a></p>
  
  <p>but there was problem with usings</p>
  
  <blockquote>
    <p>'BitmapImage' is an ambiguous reference between 'System.Windows.Media.Imaging.BitmapImage' and 'Windows.UI.Xaml.Media.Imaging.BitmapImage'</p>
  </blockquote>
  
  <p>so I used "BitmapEncoder" but it doesn't have method like Save and Frame.</p>