WPF: the best way to get a snapshot of what is controlled by Canvas

I have a WPF application and I use Canvas with 50% opacity as a cropping rectangle that can be resized and moved around the image, and every time I move it, I use CroppedBitmap to show the preview image, but it makes the application slow when I create a new CroppedBitmap every time ...

What is the best way to get the image of the canvas area?

thank!

+3
source share
1 answer

You can use VisualBrush and point it to Canvas

<StackPanel >
  <Canvas x:Name="MyCanvas" Width="10" Height="10" HorizontalAlignment="Left" ClipToBounds="True">
    <Ellipse Fill="Black" Width="10" Height="20" />
  </Canvas>
  <Border Height="30" Width="30" HorizontalAlignment="Left">
    <Border.Background>
      <VisualBrush Visual="{Binding ElementName=MyCanvas}"  />
    </Border.Background>
  </Border>
</StackPanel>
+1
source

Source: https://habr.com/ru/post/1766078/


All Articles