如何修复 VisualBrush 丢失的线? [英] How to fix VisualBrush lost line?

查看:22
本文介绍了如何修复 VisualBrush 丢失的线?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在WPF中,我们可以使用VisualBrush做一些类似ppt左侧的事情.

但是当我将 VisualBrush 缩放到小尺寸时,我发现 VisualBrush 可能会丢失矩形中的线条.就像图像一样:

您可以看到 VisualBrush 失去了底线.

但我想要的是下图:

当我尝试使用使用 RenderTargetBitmap 的 BitmapImage 获取图像并使用线性插值算法进行缩放时,将获得清晰的图像.

我可以更改 VisualBrush 的算法吗?我认为它可能使用邻域像素算法.

有没有像 VisualBrush 一样具有良好性能的打印屏幕算法.

当我将搜索键更改为 ViewBox 时,我可以找到与此相同的问题:

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:

You can see VisualBrush lost the Bottom line.

But what I want is like the below image:

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?

解决方案

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.

这篇关于如何修复 VisualBrush 丢失的线?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆