如何在WPF中拉伸位图而不平滑像素 [英] How can I stretch bitmap in WPF without smoothing pixels

查看:161
本文介绍了如何在WPF中拉伸位图而不平滑像素的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在研究用WPF编写的SEM图像处理应用程序.我有一个从Canvas派生的图像显示控件,该控件显示图像&使用DrawingVisuals进行叠加(每个层"一个).它还实现了Zoom&使用缩放和平移翻译转换,应用于DrawingVisuals.

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.

当我放大图像以查看单个像素时,它们显示得很平滑,显然是使用双线性过滤来拉伸位图的(毫不奇怪,因为WPF是通过Direct3D渲染的).但是,对于我的用例,我宁愿像在任何Photoshop之类的图像编辑器中一样,将单个像素视为清晰的方框.这就是为什么我的应用程序的用户可以缩放图像->以使其能够在像素级上进行操作.

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.

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

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

先谢谢了, 兹比涅克·弗拉斯(Zbynek Vrastil) 捷克共和国

thanks in advance, Zbynek Vrastil Czech Republic

推荐答案

最后在Experts Exchange的一些帮助下找到了答案. RenderOptions类定义了附加属性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);

起到了作用.

Zbynek Vrastil

Zbynek Vrastil

这篇关于如何在WPF中拉伸位图而不平滑像素的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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