Reputation: 2246
I know how to do this in Silverlight but I can't find enough information on how to do this in WinRT.
I read that WinRT XAML Toolkit may be able to help but the exact component, WinRT XAML Toolkit - Composition
does not seem to be compatible with Windows Universal App. I am currently developing for Windows Phone 8.1 part.
WinRT XAML Toolkit for Windows Phone 8.1 does not seem to have something like WriteableBitmap.Render
method either.
I've also read that the blit
method in WriteableBitmapEx may be able to help but I couldn't find any example on how to achieve this.
Any deas?
Upvotes: 0
Views: 135
Reputation: 1856
Simpler to use if you want to display it, in order to save you must do as the answer above:
RenderTargetBitmap renderTargetBitmap = new RenderTargetBitmap();
await renderTargetBitmap.RenderAsync(RenderedGrid);
RenderedImage.Source = renderTargetBitmap;
Upvotes: 1
Reputation: 4306
You can use RenderTargetBitmap to create image from your UIElement which contains in VisualTree.
var renderTargetBitmap = new RenderTargetBitmap();
await renderTargetBitmap.RenderAsync(uielement);
var pixels = await renderTargetBitmap.GetPixelsAsync();
var logicalDpi = DisplayInformation.GetForCurrentView().LogicalDpi;
var encoder = await BitmapEncoder.CreateAsync(encoderId, stream);
encoder.SetPixelData(
BitmapPixelFormat.Bgra8,
BitmapAlphaMode.Ignore,
(uint)renderTargetBitmap.PixelWidth,
(uint)renderTargetBitmap.PixelHeight,
logicalDpi,
logicalDpi,
pixels.ToArray());
await encoder.FlushAsync();
return renderTargetBitmap;
Upvotes: 2