1

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.

1 Answers1

1

As discussed here, you will need to cast from WriteableBitmap before you apply any AForge/Accord image operations, and cast back to WriteableBitmap after the image processing operations are completed.

Also see this answer.

Community
  • 1
  • 1
Anders Gustafsson
  • 15,837
  • 8
  • 56
  • 114
  • Ohh.. That part slipped from my mind. Thank you. I got it now working. One last question, the evaluation version of Shim.Drawing puts a red cross watermark on my image. If I wish to use one or more image processing operations, will the watermark may affect the resulting image? I will try to do a texture feature extraction on my next experiment. I think the watermark may affect the texture values. Is there any work around so that only the final image will get the watermark? I'll be purchasing the license if my experiment goes well. – Harvey Oroceo Mar 29 '16 at 15:49
  • The watermark is applied during the cast procedure only, and does not affect the image processing. So what you see in the resulting image is the actual processed image, plus a watermark painted on top of it. – Anders Gustafsson Mar 29 '16 at 15:52
  • Ohh.. I see. Thanks for the info. – Harvey Oroceo Mar 29 '16 at 15:53