I'm creating a simple image processing app in Windows Phone 8.1 that uses the Accord.net Portable Library. 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 Bitmap in Windows Phone which is under System.Drawing so that I could perform image processing methods.
The problem is I am using Open File Picker that uses BitmapImage when fetching images from the Pictures Library. Here's my code for it:
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;
}
The sample Grayscale.cs class provided in https://github.com/cureos/accord/blob/portable/Sources/Accord.Imaging/AForge/Filters/Color%20Filters/Grayscale.cs tells that I can simply use the following code so that I could perform the Grayscale filter:
Grayscale filter = new Grayscale( 0.2125, 0.7154, 0.0721 );
Bitmap grayImage = filter.Apply( image );
Whereas image should be a type of Bitmap. So as you can see, I can't use the bitmapImage variable because it is a type of BitmapImage. Another problem is, the Bitmap 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 Bitmap. The BitmapData and UnmanagedImage. However I have no idea on how to use those data types.
Any work around that I could make use of, would be greatly appreciated.