开发者

WPF: Best way to get a snapshot of what is under a Canvas control

I have a WPF app, and I use a Canvas with 50% opacity as a cropping rect that can be resized and moved over an Image, and every time it moves, I use a CroppedBitmap to show a live preview of the image, but it makes the app become slow as I create a new Cr开发者_运维百科oppedBitmap every time...

What's the best way to get an image of the area the Canvas is?

thanks!


You can use VisualBrush and point it to the 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>
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜