1

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 size.Like the image:

enter image description here

You can see VisualBrush lost the Bottom line.

But what I want is like the below image:enter image description here

When I try use the BitmapImage that use RenderTargetBitmap to get a image and use linear interpolation algorithm to zoom will get a clearness image.

Can I change VisualBrush's algorithm I think it may use neighborhood-pixels algorithm.

Are there any printscreen algorithm that have a 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 line disappear in wpf?

lindexi
  • 4,182
  • 3
  • 19
  • 65

1 Answers1

1

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.

enter image description here

walterlv
  • 2,366
  • 13
  • 73
  • Thx @walterlv ,I can zoom my rectangle to a small size.![](https://i.stack.imgur.com/jfNbD.png). But it cant use to get the input for it's not a control. – lindexi Jun 12 '17 at 13:35