I need to render an xaml element and apply a blur effect using LumiaImageSDK 3
var bitmapRended = new RenderTargetBitmap();
await bitmapRended.RenderAsync(LayoutRoot);
IBuffer buffer = await bitmapRended.GetPixelsAsync();
var target = new WriteableBitmap(bitmapRended.PixelWidth, bitmapRended.PixelHeight);
var source = new BufferImageSource(buffer);
var blur = new BlurEffect(source, 128);
var renderer = new WriteableBitmapRenderer(blur, target);
var result = await renderer.RenderAsync();
var imgBrush = new ImageBrush();
imgBrush.ImageSource = result;
Menu.Background = imgBrush;
but when i run the code i get this error:
The component cannot be found. (Exception from HRESULT: 0x88982F50)
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at System.Runtime.CompilerServices.TaskAwaiter`1.GetResult()
i think is something related to the way i convert the RenderTargetBitmap
to an IRandomAccessStream
.
the exception is raised from this line of code : var result = await renderer.RenderAsync();
it seams that the problem is a deadlock but i'm not able to find a solution
edit: code updated
Since you have a IBuffer with the result (IBuffer buffer) then skip all the buffer manipulation and just create a BufferImageSource.
var target = new WriteableBitmap(bitmapRender.PixelWidth, bitmapRender.PixelHeight);
using (var source = new BufferImageSource(buffer))
using (var blur = new BlurEffect(source , 128))
using (var renderer = new WriteableBitmapRenderer(blur, target))
{
var result = await renderer.RenderAsync();
}
That said I can't see an obvious problem with the code you wrote. I will have to look into it, but until then, have you made sure the stream is at the beginning? That is a common error with streams.