问题
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