如何在 WPF 中拉伸位图而不平滑像素

发布于 2024-08-24 06:00:27 字数 392 浏览 4 评论 0原文

我正在开发用 WPF 编写的 SEM 图像处理应用程序。我有一个图像显示控件,派生自 Canvas,它显示图像和图像。使用 DrawingVisuals 进行叠加(每个“层”一个)。它还实现了缩放和缩放功能。使用比例和平移翻译变换,应用于 DrawingVisuals。

当我放大图像以查看各个像素时,它们显示得很平滑,显然是使用双线性过滤来拉伸位图(这并不奇怪,因为 WPF 是通过 Direct3D 渲染的)。然而,对于我的用例,我宁愿将单个像素视为锐利的框,就像在 Photoshop 等任何图像编辑器中一样。这就是我的应用程序的用户缩放图像的原因 ->能够在像素级别上进行操作。

WPF 中是否有这样的选项(除了在显示位图之前手动拉伸位图之外)?我什么也没找到。

提前致谢, 兹宾内克·瓦斯蒂尔 捷克共和国

I'm working on SEM image processing application, written in WPF. I have an image display control, derived from Canvas, which displays image & overlays using DrawingVisuals (one for each "layer"). It also implements Zoom & Pan using scale & translate transform, applied on DrawingVisuals.

When I zoom in the image to see individual pixels, they are displayed smooth, evidently using bilinear filtering to stretch the bitmap (no surprise, as WPF is rendered through Direct3D). However, for my use case, I would rather see individual pixels as sharp boxes, as usual in any image editor like Photoshop. That's why user of my app zooms the image -> to be able to operate on pixel level.

Is there such option in WPF (other than manually stretching the bitmap before displaying it)? I was not able to find anything.

thanks in advance,
Zbynek Vrastil
Czech Republic

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

浅浅淡淡 2024-08-31 06:00:27

在专家交流的帮助下终于找到了答案。 RenderOptions 类定义附加属性 BitmapScalingMode,可以设置为 NearestNeighbor。所以,

RenderOptions.SetBitmapScalingMode(imageDisplay, BitmapScalingMode.NearestNeighbor);

技巧就完成了。

兹宾内克·瓦斯蒂尔

Finally found an answer, with some help from Experts Exchange. Class RenderOptions defines attached property BitmapScalingMode, which can be set to NearestNeighbor. So,

RenderOptions.SetBitmapScalingMode(imageDisplay, BitmapScalingMode.NearestNeighbor);

does the trick.

Zbynek Vrastil

南巷近海 2024-08-31 06:00:27

讨厌对事物施加抑制器,但如果 NearestNeighbor 像 GDI+ 一样工作,那么这只会给你带来有限的成功。当您增加高对比度区域的放大倍数时,您可能无法获得所需的结果。在 GDI+ 中,您会发现黑色变成蓝色,白色变成红色 - 我再次强调高对比度区域!如果 WPF 中不是这种情况,那么你很幸运!

也许 WCF 开发人员可以证实这一点?

我发现还有更多选项需要考虑,但我只能谈论 GDI+ Graphics 类,这可能对某人有用。

Graphics graph = e.Graphics;
graph.InterpolationMode = InterpolationMode.NearestNeighbor;
graph.CompositingQuality = CompositingQuality.AssumeLinear;
graph.SmoothingMode = SmoothingMode.None;

这对我有用。我认为 SmoothingMode 就是窍门。希望这对其他人有帮助。

Hate to put a dampener on things, but if NearestNeighbor works like GDI+, then this will give you a limited success. As you increase magnification in areas of high contrast you might not get the desired results. In GDI+ you find blacks becoming blue, and whites becoming red - again I stress in areas of high contrast! If this isn't the case in WPF, think yourself lucky!

Perhaps a WCF developer could confirm that?

I've found that there are more options to consider, but I can only speak for the GDI+ Graphics class, which might be useful to someone.

Graphics graph = e.Graphics;
graph.InterpolationMode = InterpolationMode.NearestNeighbor;
graph.CompositingQuality = CompositingQuality.AssumeLinear;
graph.SmoothingMode = SmoothingMode.None;

This works for me. I think the SmoothingMode is the trick. Hope this helps someone else out there.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文