Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 9 years ago.
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
接受
或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
发布评论
评论(2)
据我所知,WPF 在缩放位图时总是会进行抗锯齿处理。但是,您应该能够通过避免位图缩放来实现您的目标。
有两个步骤:
要计算所需的 ScaleTransform,请计算屏幕的 DPI,如下所示this:
然后对于位图,执行:
这将使位图的像素与设备像素完全匹配。 WPF 不会拉伸位图,因此不应该有抗锯齿。
如果您确实想在高 DPI 屏幕上拉伸图像,但不使用抗锯齿功能(例如,将所有像素加倍),只需使用您喜欢的算法在您自己的代码中拉伸位图,并将上述内容与拉伸的位图一起使用。
As far as I know, WPF always does anti-aliasing when scaling a bitmap. However you should be able to accomplish your goal by avoiding the bitmap scaling.
There are two steps:
SnapsToDevicePixels="true"
on your imageTo compute the needed ScaleTransform, compute your screen's DPI like this:
and then for the bitmap, do:
This will cause your bitmap's pixels to exactly match with the device pixels. WPF will not stretch the bitmap, so there should be no anti-aliasing.
If you do want to stretch your image on high DPI screens but do so without anti-aliasing (eg double all pixels), just stretch the bitmap in your own code using whichever algorithm you like and use the above with the stretched bitmap.
它并不是真正的抗锯齿 - 导致问题的是子像素定位,我在我的博客上写了相关内容(以及解决问题的控件):
http://www.nbdtech.com/blog/archive/2008/11/20/blurred -wpf.aspx 中的图像
It's not really anti-aliasing - it's sub pixel positioning that causing the problem, I've written about it (and about a control that solves the problem) on my blog at:
http://www.nbdtech.com/blog/archive/2008/11/20/blurred-images-in-wpf.aspx