获取像素中的文字宽度 [英] Get Text Width in Pixel
问题描述
大家好,
我需要在Pixel中获得文字宽度。但TextRenderer.MeasureText()和Graphics.MeasureString()方法无法正常工作。
所以我找到了gettextextentpoint32的C ++方法名。但我认为,我无法正确使用此方法。使用这种方法,有些单词无法正确测量。
我需要测量单词; 斜体字体宽度 [< a href =http://www.codeproject.com/Articles/14915/Width-of-text-in-italic-font?msg=5008926#xx5008926xx\"target =_ blanktitle =New Window> ^ ]喜欢这个。
请帮帮我。你能建议任何其他方式或真正的方式...
我可以编写C ++ DLL来使用我的C#项目。所以,你可以用C ++语言回答。谢谢你的回答。祝你有个美好的一天。
我的形象问题; http://tinypic.com/view.php?pic=vrvymq&s=8#。 VO3tbPmsWGw [ ^ ]
Hi everyone,
I need to get Text Width in Pixel. But TextRenderer.MeasureText() and Graphics.MeasureString() methods aren't work correctly.
So I found the C++ method name of the "gettextextentpoint32". But I think, I couldn't use this method correctly. With this method some words doesn't measure correctly.
I need to measure word like; Width of text in italic font[^] like this.
Please help me. Can you suggest any other way or true way...
I can write C++ DLL for use my C# project. So, you can answer with C++ languague. Thanks for all answer. Have a good day.
My problem with image; http://tinypic.com/view.php?pic=vrvymq&s=8#.VO3tbPmsWGw[^]
推荐答案
请参阅我对该问题的评论。对不起,但就在这时,我只知道两个解决方案,但两者都是低质量的。有人声称存在准确的解决方案,但请看这个:
http://stackoverflow.com/questions/10737399/accurately-measuring-rendering-hit-testing-and-printing-text-in-a-winforms-app [ ^ ]。
第二个解决方案很尴尬,会提供最差的表现,很可能是极度贫困:画出某些位图上的字符串以x = 0
开头,对比色为黑色白色,然后检测最右边的非黑色像素。
对不起:到目前为止,这么糟糕。 :-)
-SA
Please see my comment to the question. Sorry, but at this moment, I know only two solutions, but both are of low quality. There is a claim that accurate solution exist, but please see this:
http://stackoverflow.com/questions/10737399/accurately-measuring-rendering-hit-testing-and-printing-text-in-a-winforms-app[^].
The second solution is just quite awkward and would provide poorest performance, very likely prohibitively poor: draw the string on some bitmap starting withx = 0
in contrast color, say, white on black, and then detect rightmost non-black pixel.
Sorry: so far, so bad. :-)
—SA
这篇关于获取像素中的文字宽度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!