title: Converting BitmapImage to Bitmap (Windows Phone 8.1 using Accord.net Portable Library)
body: <p>I'm creating a simple image processing app in <strong>Windows Phone 8.1</strong> that uses the <strong>Accord.net Portable Library</strong>. My main goal is to filter a colored image from my pictures library (which are in .jpeg) by using Grayscale. The Accord.net Portable library allows the use <strong>Bitmap</strong> in Windows Phone which is under <strong>System.Drawing</strong> so that I could perform image processing methods.</p>
  
  <p>The problem is I am using <strong>Open File Picker</strong> that uses <strong>BitmapImage</strong> when fetching images from the Pictures Library. Here's my code for it:</p>
  
  <pre><code>public async void ContinueFileOpenPicker(FileOpenPickerContinuationEventArgs args)
      {
          if (args.Files != null)
          {
              StorageFile file = args.Files[0];
              bitmapImage = new BitmapImage();
  
              using (var stream = await file.OpenReadAsync())
              {
                  await bitmapImage.SetSourceAsync(stream);
              }
          }
          img_Original.Source = bitmapImage;
      }
  </code></pre>
  
  <p>The sample Grayscale.cs class provided in <a href="https://github.com/cureos/accord/blob/portable/Sources/Accord.Imaging/AForge/Filters/Color%20Filters/Grayscale.cs" rel="nofollow">https://github.com/cureos/accord/blob/portable/Sources/Accord.Imaging/AForge/Filters/Color%20Filters/Grayscale.cs</a> tells that I can simply use the following code so that I could perform the Grayscale filter:</p>
  
  <pre><code>Grayscale filter = new Grayscale( 0.2125, 0.7154, 0.0721 );
  Bitmap grayImage = filter.Apply( image );
  </code></pre>
  
  <p>Whereas <strong>image</strong> should be a type of <strong>Bitmap</strong>. So as you can see, I can't use the <em>bitmapImage</em> variable because it is a type of <strong>BitmapImage</strong>. Another problem is, the <strong>Bitmap</strong> doesn't contain any constructor (unlike when in WinForms). So I am really out of options on how I would be able to apply the Grayscale filter to the existing image. Another information that might help is that when I hover to filter.Apply constructor is that it contains data types other than that <strong>Bitmap</strong>. The <strong>BitmapData</strong> and <strong>UnmanagedImage</strong>. However I have no idea on how to use those data types.</p>
  
  <p>Any work around that I could make use of, would be greatly appreciated.</p>