-api-id | -api-type |
---|---|
M:Windows.UI.Xaml.Media.Imaging.RenderTargetBitmap.RenderAsync(Windows.UI.Xaml.UIElement) |
winrt method |
Renders a snapshot of a UIElement visual tree to an image source.
A UIElement that represents the visual tree fragment to render.
An IAsyncAction object that you can use to control the asynchronous operation.
The rendered image isn't returned by this method. But after it returns, so long as the async Status value doesn't indicate an error, the RenderTargetBitmap that called it will have valid image info. The RenderTargetBitmap can then be assigned in code as an image source for an Image control or ImageBrush instance.
If you need a pixel buffer representation of the rendered content and not just an image source, use GetPixelsAsync after calling RenderAsync.
This is an async method, so there's no guarantee of exact frame synchronization with the UI source. See Remarks in RenderTargetBitmap for info on some other limitations.
You can pass null for the element parameter, and that renders the root visual tree of the app.
There are a few scenarios for XAML-composed visual content that you can't capture to a RenderTargetBitmap:
- Video content in a MediaElement or CaptureElement can't be captured using RenderTargetBitmap. That includes capturing frames from within video content.
- Custom Microsoft DirectX content (your own swap chain) inside a SwapChainBackgroundPanel or SwapChainPanel can't be captured using RenderTargetBitmap.
- Content that's in the tree but with its Visibility set to Collapsed won't be captured.
- Content that's not directly connected to the XAML visual tree and the content of the main window won't be captured. This includes Popup content, which is considered to be like a sub-window.
- For Windows Phone 8.x app: the contents of a WebView control can't be rendered into a RenderTargetBitmap.
- Content that can't be captured will appear as blank in the captured image, but other content in the same visual tree can still be captured and will render (the presence of content that can't be captured won't invalidate the entire capture of that XAML composition).
- Content that's in the XAML visual tree but offscreen can be captured, so long as it's not Visibility = Collapsed or in the other restricted cases.
RenderAsync(UIElement, Int32, Int32), XAML render to bitmap sample