Modifying the kerning in System.Drawing.Graphics.DrawString()

倾然丶 夕夏残阳落幕 提交于 2019-12-22 07:56:21

问题


I'm rendering text onto an image using the System.Drawing.Graphics class, and the DrawString() method.

I need to generate the text for this image in a very specific way so that it exactly - pixel for pixel - matches an existing image.

The problem is that the text generated by DrawString() has a different kerning to the text in the existing image (my best guess is approximately 0.5 - 1 pixel per letter).

Can anyone tell me if it's possible to modify the kerning while using this namespace and method?

Also, it's a custom font that we're using and we had to convert this from open-type (which the source image used) to true-type. Might the kerning have been modified at this stage?


回答1:


http://blog.stevex.net/rendering-text-using-the-net-framework/

The problem with these is that text kerning is measured differently – more accurately – but in a way that is often incompatible with the way app developers want to use these functions.

The solution:

ExtTextOut wasn’t smart enough to do this sort of kerning, so you don’t have this problem. Unfortunately the .NET framework doesn’t have any text drawing function that you can fall back on, so the only way to get the old behaviour is through P/Invoke to the ExtTextOut function in GDI.

The link has some example code.. hope that helps!



来源:https://stackoverflow.com/questions/3235103/modifying-the-kerning-in-system-drawing-graphics-drawstring

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!