I would like to use a FrameworkElement (such as a Panel) as an Image (to use the Nokia Image SDK). I would like to apply an effect not on an image but on a FrameworkElement.
I've been struggling trying to use a FrameworkElement as a writeableBitmap then to a stream for my FilterEffect.
Here is what i have done :
private async void testCartoon_Tap(object sender, System.Windows.Input.GestureEventArgs e)
{
//the panel I want as an Image
var rootElement = ContentPanel as FrameworkElement;
WriteableBitmap myWB = new WriteableBitmap(rootElement,null);
byte[] bytes = myWB.ToByteArray();
MemoryStream stream = new MemoryStream();
await stream.WriteAsync(myWB.ToByteArray(),0,bytes.Count());
stream.Seek(0, SeekOrigin.Begin);
var backgroundSource = new StreamImageSource(stream);
var filterEffect = new FilterEffect(backgroundSource);
CartoonFilter cartoonFilter = new CartoonFilter();
filterEffect.Filters = new[] { cartoonFilter };
var renderer = new WriteableBitmapRenderer(filterEffect, _cartoonImageBitmap);
_cartoonImageBitmap = await renderer.RenderAsync();
ImageCartoon.Source = _cartoonImageBitmap;
}
The CartoonFilter is one of the NokiaImagingSDK Filter.
I defined my _cartoonImageBitmap like this :
_cartoonImageBitmap = new WriteableBitmap((int)ImageCartoon.Width, (int)ImageCartoon.Height);
and ImageCartoon in xaml :
<Image x:Name="ImageCartoon" Width="456" Height="240" Grid.Row="1" ></Image>
I get the exception : "Value doesn't fall within the expected range" at line
_cartoonImageBitmap = await renderer.RenderAsync();
Do you have any idea why ?
Is there a better way to get a stream out of a FrameworkElement ?
(I know i can save the writeableBitmap into the filestorage before reading it but I would like to avoid saving the image to increase performance).
Thanks a lot for your help.
I found the solution : the problem came from the WriteAsync method. here is what I've done :
I just changed with SaveJpeg and it works now. Thanks for your help.