如何指定WPF Image使用的图像缩放算法?

发布于 2024-09-03 09:00:26 字数 385 浏览 3 评论 0原文

有没有办法指定如何在 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 技术交流群。

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

发布评论

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

评论(2

荒芜了季节 2024-09-10 09:00:26

您可以设置 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.

陌路黄昏 2024-09-10 09:00:26

我通过重写 Image 子类中的 OnRender 并在绘制图像之前设置 VisualBitmapScalingMode 来修复此问题:

class MyImage : System.Windows.Controls.Image
  {
    protected override void OnRender(DrawingContext dc)
    {
      this.VisualBitmapScalingMode = System.Windows.Media.BitmapScalingMode.NearestNeighbor;
      base.OnRender(dc);
    }
  }

I fixed this by overriding OnRender in my Image subclass, and setting the VisualBitmapScalingMode before drawing the image:

class MyImage : System.Windows.Controls.Image
  {
    protected override void OnRender(DrawingContext dc)
    {
      this.VisualBitmapScalingMode = System.Windows.Media.BitmapScalingMode.NearestNeighbor;
      base.OnRender(dc);
    }
  }
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文