简体   繁体   English

SetCompatibleTextRenderingDefault(true)和Graphics.DrawString()文本呈现

[英]SetCompatibleTextRenderingDefault(true) and Graphics.DrawString() text rendering

I'm writing a C# (ActiveX) plugin for an application that uses SetCompatibleTextRenderingDefault(true) (forces .net 1.1 text rendering style) This setting mangles some of the text I output with Graphics.DrawString() causing it to look slightly smudged and bolded. 我正在为使用SetCompatibleTextRenderingDefault(true) (强制.net 1.1文本呈现样式)的应用程序编写C#(ActiveX)插件。此设置使我用Graphics.DrawString()输出的某些文本SetCompatibleTextRenderingDefault(true)导致其看起来有些脏污,加粗。 Unlike individual controls neither the Graphics class nor the BitMap have UseCompatibleTextRendering properties that can be used to override the individual behavior. 与单独的控件不同, Graphics类和BitMap具有UseCompatibleTextRendering属性, UseCompatibleTextRendering属性可用于覆盖单独的行为。 Short of fiddling around to try and figure out what's special about the places where I'm drawing text that doesn't get mangled is there anything I can do about this? 没办法摆弄一下,想弄清楚我正在绘制的文字不乱的地方有什么特别的办法吗?

The app my plugin is for belongs to a third party so simply changing the SetCompatibleTextRenderingDefault call it inflicts on me is not an option. 我的插件所针对的应用属于第三方,因此仅更改SetCompatibleTextRenderingDefault我造成的SetCompatibleTextRenderingDefault调用是SetCompatibleTextRenderingDefault的。

Edit: The 'special' thing appears to be the color of the background and how it's affecting the anti-aliasing used; 编辑:“特殊”的东西似乎是背景的颜色以及它如何影响使用的抗锯齿; so fiddling to fix it by how I setup the rectangles doesn't seem to be an option. 所以通过我设置矩形的方式来修复它似乎不是一个选择。

我建议使用TextRenderer.DrawText而不是Graphics.DrawString即使禁用兼容的文本呈现,它似乎也会产生更清晰,更一致的结果。

I found a fix for my problem by changing the TextRenderingHint to SingleBitPerPixelGridFit which is the default when not using compatible text rendering. 我通过将TextRenderingHint更改为SingleBitPerPixelGridFit找到了解决此问题的方法,这是不使用兼容文本呈现时的默认设置。 When it's instead set to true it uses a the ClearType enumeration except that for whatever reason unlike normal cleartype text the results are ugly and extremely hard to read. 相反,将其设置为true时,它将使用ClearType枚举,但出于某种原因,它不同于普通的cleartype文本,其结果很难看而且很难读。

textGraphics.TextRenderingHint = 
             System.Drawing.Text.TextRenderingHint.SingleBitPerPixelGridFit;

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM