RenderTargetBitmap.RenderAsync(UIElement) method

Applies to Windows and Windows Phone

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

Syntax


Public Function RenderAsync(
  element As UIElement 
) As IAsyncAction

Parameters

element

Type: UIElement

A UIElement that represents the visual tree fragment to render.

Return value

Type: IAsyncAction

When this method returns, an IAsyncAction object that can be used 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 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 XAML visual tree but offscreen won't be captured. 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).

Requirements

Minimum supported client

Windows 8.1

Minimum supported server

Windows Server 2012 R2

Minimum supported phone

Windows Phone 8.1 [Windows Runtime apps only]

Namespace

Windows.UI.Xaml.Media.Imaging
Windows::UI::Xaml::Media::Imaging [C++]

Metadata

Windows.winmd

See also

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

 

 

Show:
© 2014 Microsoft