在离屏绘制时(例如 RenderTargetBitmap)可以得到 TextFormattingMode=Display 吗?

发布于 2025-01-01 02:29:04 字数 568 浏览 0 评论 0原文

我正在 WPF 中绘制某些图像,这些图像将由游戏(由第三方开发)显示。我目前使用 RenderTargetBitmap 生成图像。不幸的是,这似乎只支持 Ideal 文本格式模式,导致小字体模糊。该应用程序是第三方游戏,因此无法使用图像。

我可以告诉 RenderTargetBitmap 假设它正在绘制用于当前监视器之一的图像吗?是否有其他方法让 WPF 使用 Display 渲染模式进行离屏绘制?

我理解为什么这在理论上似乎是错误的,但在实践中,我认为这并不是一件不合理的事情:

  • Display 模式允许的事情之一是别名文本,它在小尺寸下看起来比理想渲染更好,并且完全独立于伽玛等显示器属性。
  • 在 ClearType 中渲染的小显示模式文本的屏幕截图在任何屏幕上看起来都比理想模式文本好得多,即使是那些具有不同伽玛值的屏幕。

WPF 渲染引擎可以做到这一点,还是我必须退回到 GDI? (使用 Aliased 或 ClearType 离屏渲染没有任何困难)

I'm drawing certain images in WPF which will be displayed by a game (developed by a third party). I currently produce the images using a RenderTargetBitmap. Unfortunately it seems that this only supports the Ideal text formatting mode, resulting in blurry small fonts. The application is a third-party game and thus there's no way around using images.

Can I tell the RenderTargetBitmap to assume that it's drawing an image destined for one of the current montiors? Is there another way to get WPF to use the Display rendering mode for off-screen drawing?

I understand why this might seem wrong in the theoretical sense, but in practice there are reasons why I think this is not an unreasonable thing to do:

  • One of the things the Display mode allows is aliased text, which looks better at small sizes than the Ideal rendering, and is completely independent of monitor properties such as gamma.
  • A screenshot of small Display-mode text rendered in ClearType looks far better on any screen, even those with different gamma, than Ideal-mode text.

Can the WPF rendering engine do this, or do I have to fall back onto GDI? (which has no difficulties with using Aliased or ClearType rendering off-screen)

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

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

发布评论

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

评论(2

天气好吗我好吗 2025-01-08 02:29:04

当然没有明显的方法可以做到这一点。我想绘制图像从来都不是 WPF 的目标;事实上,它在大多数时候都能很好地做到这一点,这一定是偶然的。

There is certainly no obvious way of doing this. I guess drawing to images was never a goal of WPF; the fact that it can actually do this fairly well most of the time must be accidental.

莫多说 2025-01-08 02:29:04

现在看来这行得通。其他人可以验证吗?以下是相关代码:

var textBlock = new TextBlock();
textBlock.Text = "Hello World";
textBlock.FontFamily = new System.Windows.Media.FontFamily("Arial");
textBlock.Background = System.Windows.Media.Brushes.Transparent;
textBlock.Foreground = System.Windows.Media.Brushes.Black;
textBlock.FontSize = 50;

// . Set Formatting Mode Works! Setting the rendering mode doesn't. 
System.Windows.Media.TextOptions.SetTextFormattingMode(textBlock, System.Windows.Media.TextFormattingMode.Display);

编辑:忘记提及我正在使用 .NET 4.5 框架

Edit2:显示和理想之间的差异在较小的字体大小下尤其明显。

It seems that this works now. Could someone else verify? Here's the relevant code:

var textBlock = new TextBlock();
textBlock.Text = "Hello World";
textBlock.FontFamily = new System.Windows.Media.FontFamily("Arial");
textBlock.Background = System.Windows.Media.Brushes.Transparent;
textBlock.Foreground = System.Windows.Media.Brushes.Black;
textBlock.FontSize = 50;

// . Set Formatting Mode Works! Setting the rendering mode doesn't. 
System.Windows.Media.TextOptions.SetTextFormattingMode(textBlock, System.Windows.Media.TextFormattingMode.Display);

Edit: Forgot to mention I'm using the .NET 4.5 framework

Edit2: The difference between Display and Ideal is especially noticeable at smaller font sizes.

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