Skip to content

Latest commit

 

History

History
45 lines (31 loc) · 3.49 KB

rendertargetbitmap_renderasync_318933921.md

File metadata and controls

45 lines (31 loc) · 3.49 KB
-api-id -api-type
M:Microsoft.UI.Xaml.Media.Imaging.RenderTargetBitmap.RenderAsync(Microsoft.UI.Xaml.UIElement)
winrt method

Microsoft.UI.Xaml.Media.Imaging.RenderTargetBitmap.RenderAsync

-description

Renders a snapshot of a UIElement visual tree to an image source.

-parameters

-param element

A UIElement that represents the visual tree fragment to render.

-returns

An IAsyncAction object that you can use to control the asynchronous operation.

-remarks

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.

XAML visuals and RenderTargetBitmap capture capabilities

There are a few scenarios for XAML-composed visual content that you can't capture to a RenderTargetBitmap:

  • Video content in a MediaPlayerElement 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.
  • 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.

-examples

-see-also

RenderAsync(UIElement, Int32, Int32), XAML render to bitmap sample