问题描述
我的新应用程序将具有丰富的界面,该界面应使用透明的图标/图像等即时调整大小.对于此应用程序,我试图决定使用新的 Direct2D API反对旧的GDI.缺点之一当然是它不能在XP上运行,尽管我发现有些棘手的问题需要决定:
My new application will feature a rich interface which should be resizable on-the-fly uses transparent icons/images etc. For this application I'm trying to decide on using the new Direct2D API against the good old GDI. One of the downsides is of course it does not run on XP, although I've found a bit nastier issues to decide upon:
-
我注意到在Direct2D环境中输出文本似乎有点模糊(尽管作为功能销售).只需在启用了硬件加速功能(或IE9)的Firefox 4中查看文本即可.似乎是由于在Direct2D文本中不像GDI那样遵守(像素)网格.有没有一种方法可以强制Direct2D使其附着在像素网格上,从而解决此问题?
I noticed that outputting text in a Direct2D environment seems a bit blurry (although marketed as a feature). Just look at the text in Firefox 4 with hardware acceleration enabled (or IE9). It seems to be due to the fact that in Direct2D text does not adhere to the (pixel) grid like GDI does. Is there a way to force Direct2D to make it adhere to the pixel grid and thus fixing this issue?
Is there really such an improvement in speed? I tried to understand this article and what I make from it is that in Windows 7 and XP (not Vista?) the GDI is already hardware accelerated where it can. E.g. in my application I use a lot of memory DC's which are just BitBlt
ed into place and drawing transparent images/anti-aliased lines etc are being drawn using AlphaBlend
. And that last one is definitely hardware accelerated since I measured speed while testing my routines.
那么,您将把钱放在哪里? Direct2D值得您为之烦恼,还是只是坚持使用旧的GDI?还是您有其他建议?
So where would you put your money? Is Direct2D worth the hassle or would you just stick to the good old GDI? Or would you suggest something else?
注意:我用C ++编程,不使用MFC.
Note: I'm programming in C++ btw, no use of MFC.
推荐答案
解决问题的方法非常简单. Direct2D是高度可配置的,其中包括文本渲染和提示.如果要使其呈现文本以匹配GDI的呈现(即非常紧密的像素对齐),只需:
The fix to your problem is very simple. Direct2D is highly configurable, and that includes text rendering and hinting. If you want to make it render text to match GDI's rendering (that is, very tight pixel alignment) just:
- 在呈现目标上调用SetTextRenderingParams函数 http://msdn.microsoft.com/en-us/library/windows/desktop/dd316898%28v=vs.85%29.aspx
- 传入一个IDWriteRenderingParams,您可以在其上调用值为GDI_CLASSIC或GDI_NATURAL的SetRenderingMode(建议使用自然值).也可以通过多种其他方式配置此对象,包括变量ClearType,伽玛值和对比度.
由于另一个答案变得毫无用处,并且破坏了Direct2D中的渲染,因此让我提供Direct2D文本渲染的另一个概述.非常非常好.与Mac上的不同,在Mac上它们基本上不提示字体,而文本实际上显示为模糊,默认情况下Direct2D仅在Y方向强烈提示.这是有道理的,因为您的显示器可能在垂直方向上具有约96 dpi的分辨率,但是在进行亚像素抗锯齿处理时,水平分辨率超出了合理的人类感知范围.它的ClearType用法和提示也比GDI更加微妙.与Direct2D相比,GDI文本的边缘往往非常鲜艳.如今,我发现GDI文本看起来非常苛刻,并且更喜欢Firefox和IE中的Direct2D文本进行长时间阅读.
Since the other answer went out of its way to be most unhelpful and bash the rendering in Direct2D, let me provide another overview of Direct2D's text rendering. It is very, very good. Unlike on the Mac, where they basically do not hint fonts and the text actually comes out as blurry, Direct2D by default strongly hints in the Y direction only. This makes sense since your monitor probably has about 96 dpi vertically, but with sub-pixel anti-aliasing the horizontal resolution is beyond the range of reasonable human perception. It is also a lot more subtle in its ClearType usage and hinting than GDI was. The edges of GDI text tend to be very colorful compared to Direct2D. I find GDI text very harsh-looking nowadays and much prefer the Direct2D text in Firefox and IE for long reading sessions.
因此,由于多种原因,默认模式可能对您显示为模糊".
Therefore, there are several reasons that the default mode probably appears "blurry" to you.
- 首先,花点时间在控制面板中运行ClearType调谐器程序.您会惊讶于Direct2D程序中的差异.
- 无论它有多好,当将其放在应用程序中GDI分隔的文本旁边时,它总是显得很奇怪.尝试将用户界面中的所有内容都做成一个,或者将内容区域与其他区域清楚地区分开.如果您决定使所有内容都使用GDI分隔,只需使用上述方法将Direct2D设置为GDI分隔的文本模式即可.
- 您尚未从Windows Update安装所有可用的更新. DirectWrite和IE已经有好几种.确保全部安装并重新启动以查看改进.
- 您只是还不习惯.
- 在你的脑海中.真的.一旦开始大量考虑文本渲染,您可能会发现自己注意到了不存在的问题".这个问题的另一个答案是一个很好的例子.他指出,他认为Visual Studio 2010中的文本比2008年模糊,但实际上它们是像素完美的副本.不相信我吗? VS开发人员实际上自己提供了一些比较.我敢打赌,你不能说出区别. http://blogs .msdn.com/b/text/archive/2010/03/05/additional-wpf-text-clarity-improvements.aspx
- First of all, take the time to run the ClearType tuner program in the control panel. You will be amazed at the difference in Direct2D programs.
- No matter how good it is, it will always appear strange when you place it next to GDI-spaced text in your application. Try making everything in the UI one or the other, or clearly distinguish the content area from the other areas. If you decide to make everything GDI-spaced, just use the method I described above to set Direct2D to GDI-spaced text mode.
- You haven't installed all available updates from Windows Update. There have been several for DirectWrite and IE. Make sure you install them all and restart to see the improvements.
- You just haven't gotten used to it yet.
- It's in your head. Really. Once you start thinking about text rendering a lot, you'll probably find yourself noticing "problems" that aren't there. The other answer to this question is the perfect example. He states that he thinks the text in Visual Studio 2010 is blurrier than 2008, but they are actually pixel perfect copies. Don't believe me? The VS developers actually provided some comparisons yourself. I bet you can't tell the difference. http://blogs.msdn.com/b/text/archive/2010/03/05/additional-wpf-text-clarity-improvements.aspx
这篇关于Direct2D界面和模糊文本问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!