如何指定WPF Image使用的图像缩放算法?
有没有办法指定如何在 Image
元素中放大图像,并将 LayoutTransform
设置为 ScaleTransform
并使用整数值 ScaleX 和 ScaleY 吗?
我想清晰地显示缩放后的图像(即使用“最近邻”缩放),而不会模糊。 (想象一下您希望位图编辑程序在放大时如何表现)。
我注意到 Image
上受保护的属性 VisualBitmapScalingMode
,因此创建了 Image
的子类,将此属性设置为 BitmapScalingMode.NearestNeighbor
。然而,这没有效果。
Is there a way to specify how an image is scaled up in an Image
element with LayoutTransform
set to a ScaleTransform
with integer values for ScaleX
and ScaleY
?
I want to display the scaled image crisply (ie using 'nearest neighbour' scaling), with no blurring. (Imagine how you would want a bitmap editing program to behave when zooming in).
I noticed the protected property VisualBitmapScalingMode
on Image
, so created a subclass of Image
that sets this property to BitmapScalingMode.NearestNeighbor
. However, this had no effect.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可以设置 Image 控件的 XAML 中的 RenderOptions.BitmapScalingMode 属性。不需要继承Image类。
You can set the RenderOptions.BitmapScalingMode property in the XAML for the Image control. There's no need to inherit the Image class.
我通过重写 Image 子类中的 OnRender 并在绘制图像之前设置 VisualBitmapScalingMode 来修复此问题:
I fixed this by overriding OnRender in my Image subclass, and setting the VisualBitmapScalingMode before drawing the image: