阅读背景:

修改system . draw . graphics . drawstring()中的kerning

来源:互联网 

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

我使用System.Drawing将文本渲染到图像上。图形类,以及DrawString()方法。

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).

问题是由DrawString()生成的文本与现有图像中的文本具有不同的字距(我的最佳猜测是每个字母大约为0.5 - 1像素)。

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

谁能告诉我在使用这个名称空间和方法时是否有可能修改kerning ?

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?

另外,我们使用的是自定义字体,我们必须将它从open-type(源图像使用的)转换为true-type。可能在这个阶段已经修改过了吗?

1 个解决方案

#1


3  

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

https://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.

ExtTextOut还不够聪明,不能做这种字处理,所以你没有这个问题。不幸的是。net框架没有任何文本绘制功能,所以获得旧行为的唯一方法是通过P/Invoke到GDI中的ExtTextOut函数。

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

这个链接有一些示例代码。希望会有帮助!


分享到: