WPF v4 中的图像调整大小锯齿,但 v3.5 下不支持

发布于 2024-09-04 16:13:14 字数 537 浏览 7 评论 0原文

我正在使用 WPF 进行图像调整大小管道,该管道在 .NET v3.5 下运行良好。我刚刚将项目升级到目标 v4.0,现在所有调整大小的图像都存在严重别名。图像管道代码均未更改。

  1. 默认 WPF 设置在 v3.5 和 v4.0 之间是否发生了变化?

  2. 如何在 WPF 中控制已调整大小的位图图像的抖动?

我正在使用 BitmapImage、DrawingVisual、DrawingContext、RenderTargetBitmap、BitmapEncoder 和BitmapFrame 但我没有看到任何与抖动相关的属性。 GDI+ 有很多设置,所以我猜我遗漏了一些东西。

更新:我见过的所有解决方案似乎都假定 Window 对象或 XAML 环境。它在没有 UI 的 Windows 服务内运行。我需要一种以编程方式影响此设置的方法。

我特意从 GDI+ 切换到 WPF,因为 GDI+ 在长时间运行的进程(例如服务和应用程序)中存在内存泄漏。网络应用程序。

I am using WPF for an image resizing pipeline which has been working beautifully under .NET v3.5. I just upgraded the project to target v4.0 and now all of my resized images are heavily aliased. None of the image pipeline code has changed.

  1. Has a default WPF setting changed between v3.5 and v4.0?

  2. How do I control the dithering of my resized bitmap images in WPF?

I'm using BitmapImage, DrawingVisual, DrawingContext, RenderTargetBitmap, BitmapEncoder, and BitmapFrame but I'm not seeing any properties related to dithering. GDI+ had a bunch of settings, so I'm guessing that I'm missing something.

Update: it appears that all of the solutions I've seen assume a Window object or XAML environment. This runs inside a Windows Service which has no UI. I need a way to programmatically affect this setting.

I specifically switched from GDI+ to WPF because GDI+ has memory leaks in long running processes like services & web apps.

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

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

发布评论

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

评论(2

甚是思念 2024-09-11 16:13:14

我能够影响 BitmapScalingMode 设置的唯一方法是从 DrawingVisual 类继承并通过其受保护的访问器设置它:

// exposes BitmapScalingMode (also works for other protected properties)
public class MyDrawingVisual : DrawingVisual
{
    public BitmapScalingMode BitmapScalingMode
    {
        get { return this.VisualBitmapScalingMode; }
        set { this.VisualBitmapScalingMode = value; }
    }
}

如果其他人知道更好的方法设置这个的方式,我会很高兴听到它。

看起来这会起作用:

RenderOptions.SetBitmapScalingMode(myDrawingVisual, BitmapScalingMode.HighQuality);

……但事实并非如此。显然,位于 XAML 窗口运行时之外必然意味着它无法设置适当的值。

The only way I've been able to affect the setting of BitmapScalingMode is to inherit from the DrawingVisual class and set it via its protected accessor:

// exposes BitmapScalingMode (also works for other protected properties)
public class MyDrawingVisual : DrawingVisual
{
    public BitmapScalingMode BitmapScalingMode
    {
        get { return this.VisualBitmapScalingMode; }
        set { this.VisualBitmapScalingMode = value; }
    }
}

If anyone else knows of a better way to set this, I would be excited to hear about it.

It seems that this would work:

RenderOptions.SetBitmapScalingMode(myDrawingVisual, BitmapScalingMode.HighQuality);

...but it does not. Apparently being outside of the XAML windowing runtime must mean that it cannot set the appropriate values.

下雨或天晴 2024-09-11 16:13:14

默认的 BitmapScalingMode 在 3.0 中是 Fant,但在 4.0 中现在是 BiLinear。您可以通过几种不同的方式更改默认值。几个 此处描述

The default BitmapScalingMode was Fant in 3.0 but in 4.0 it is now BiLinear. You can change the default a few different ways. A couple described here.

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