[UWP] How to capture a Node with transparent.

Aloento 81 Reputation points

For example, I have a UWP app, which has a node "Button" on it.
Now, I want to make a snap for this Button. And, the output only includes this Button.

For JavaFX, we have the function "node.snapshot()", how about C# with UWP?

Universal Windows Platform (UWP)
An object-oriented and type-safe programming language that has its roots in the C family of languages and includes support for component-oriented programming.
10,385 questions
0 comments No comments
{count} votes

Accepted answer
  1. Yan Gu - MSFT 2,676 Reputation points


    Welcome to Microsoft Q&A.

    You could use RenderTargetBitmap class(which represents an image source that can be populated with the combined contents of a XAML visual tree) to do the job.

    For example:

        <Button x:Name="capturedButton" Content="capture me" Margin="10"/>  
        <Button x:Name="button" Content="click me" Margin="10" Click="button_Click"/>  
        <Image x:Name="image" Margin="10" Width="200" Height="200" Stretch="None"/>  
    private async void button_Click(object sender, RoutedEventArgs e)  
        RenderTargetBitmap renderTargetBitmap = new RenderTargetBitmap();  
        await renderTargetBitmap.RenderAsync(capturedButton);  
        image.Source = renderTargetBitmap;  

    If the response is helpful, please click "Accept Answer" and upvote it.
    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

    1 person found this answer helpful.

0 additional answers

Sort by: Most helpful