How to fix a lost VisualBrush string?

In WPF, we can use VisualBrush to do something like ppt on the left side.

But I see that VisualBrush can lose a line in a Rectangle when I scale VisualBrush to a small size. As picture:

enter image description here

You can see that VisualBrush has lost the bottom line.

But I want, as shown below: enter image description here

When I try to use BitmapImage, which use RenderTargetBitmap, to get the image and use the linear interpolation algorithm to zoom in, you get a sharpness image.

Can I change the VisualBrush algorithm, I think it can use the algorithm with neighboring pixels.

Is there any printing algorithm that has good performance like VisualBrush.

When I change my search key to ViewBox , I can find the same question as this one: how to avoid a single pixel string in wpf?

+1
source share
1 answer

There is a class called TransformedBitmap that can scale your RenderTargetBitmap using the default scaling algorithm.

Use the following code:

 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 tried this method in my demo and got the result below. You may notice that the small rectangle in the upper left corner has not lost anything.

enter image description here

+1
source

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


All Articles