Generating Dynamic Images with RenderTargetBitmap

RenderTargetBitmap enables you to take a screenshot of any UIElement, even your entire Page! To use it, instantiate one and then call its RenderAsync method with the root UIElement to capture:

RenderTargetBitmap rtb = new RenderTargetBitmap();await rtb.RenderAsync(element);

Because RenderTargetBitmap is an ImageSource, you can use it as the source of any Image element. To extract the image data to use for other purposes, you call GetPixelsAsync to get back an IBuffer:

IBuffer buffer = await rtb.GetPixelsAsync();

From this point, you can interact with the IBuffer the same way you would with one obtained from WriteableBitmap, such as calling ...

Get XAML Unleashed now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.