How to use the Nokia Imaging SDK's BlendFilter on WP8?

1k views Asked by At

I'm staring with the Nokia Imaging SDK to play a little with it. Now, I'm facing the problem where I have an Image which already exists (in a folder in my visual studio solution) and I want to convert this image in order to use it in the BlendFilter class of the Nokia Imaging SDK. However I don't know how to use it.

I was trying to convert the existing image in a stream and then pass it as a parameter to the BlendFilter constructor. But not luck. The compiler says that the best overload method match ... has some invalid arguments.

This is the way I'm trying to load the existing image to a stream:

Image image = new Image();
image.Source = new BitmapImage(new Uri("/Images/Template3.2.png", UriKind.Relative));

BitmapImage bitImage = new BitmapImage(new Uri("/Images/Template3.2.png", UriKind.Relative));

WriteableBitmap Bitmap = new WriteableBitmap(bitImage);

And then:

var BlendFilter = new BlendFilter(bitImage, BlendFunction.Add);  --> the compiler error is here

Does anyone know how to use the BlendFilter class? any example would be very helpful.

Regards!

1

There are 1 answers

1
David Božjak On BEST ANSWER

Blend filter takes an IImageProvider as input. That means you can use any of the X-ImageSource classes as input and it will do all the work internally.

If you have a stream of the image I suggest you create an StreamImageSource and pass that to BlendFilter.

The list of different image sources is quite long, I suggest you look into the documentation and chose the one that is most appropriate to you.

Here is an example that takes a stream of an image as input, and blends a new image on top of it. For simplicity the other image is just an image filled with one color (ColorImageSource), but you can set any IImageProvider as source: chose the most convenient one.

using (var backgroundSource = new StreamImageSource(stream))
using (var filterEffect = new FilterEffect(backgroundSource))
{
    using (BlendFilter blendFilter = new BlendFilter()) 
    {
        var size = new Windows.Foundation.Size(400, 400);
        var color = Windows.UI.Color.FromArgb(250, 128, 255, 200);

        blendFilter.ForegroundSource = new ColorImageSource(size, color);
        blendFilter.BlendFunction = BlendFunction.Add;

        filterEffect.Filters = new[] { blendFilter };

        var result = await new JpegRenderer(filterEffect).RenderAsync();
    }
}