How to fix VisualBrush lost line?

后端 未结 1 1898
你的背包
你的背包 2021-01-15 19:09

In WPF ,we can use VisualBrush do some thing like ppt\'s left side.

But I see the VisualBrush may lost the line in Rectangle when I zoom the VisualBrush to a small s

相关标签:
1条回答
  • 2021-01-15 19:38

    There is a class named TransformedBitmap which can scale your RenderTargetBitmap with default scaling algorithm.

    Use the code below:

    public static BitmapSource ToBitmapSource(this Visual visual, Size size)
    {
        var bounds = VisualTreeHelper.GetDescendantBounds(visual);
        var width = (int) Math.Round(bounds.Width);
        var height = (int) Math.Round(bounds.Height);
        var bitmap = new RenderTargetBitmap(width, height, 96.0, 96.0, PixelFormats.Pbgra32);
        bitmap.Render(visual);
        return new TransformedBitmap(bitmap, new ScaleTransform(size.Width / width, size.Height / height));
    }
    

    I've tried this method in my demo and got the result below. You may noticed that the small rectangle in the left-top corner lost nothing.

    0 讨论(0)
提交回复
热议问题