How to measure the pixel width of the string drawed over Drawing.Bitmap in .NET?

可紊 提交于 2020-01-04 02:47:11

问题


I am generating a .png image that contains a text dynamically written.

I need to create the bitmap with the minimum width for file size reasons.

How do I do this?


回答1:


Use Graphics.MeasureString() to compute the width.




回答2:


You can also use TextRenderer for slightly more accuracy. See this article for differences between this and Graphics.MeasureString :

http://msdn.microsoft.com/en-us/magazine/cc751527.aspx



来源:https://stackoverflow.com/questions/2555739/how-to-measure-the-pixel-width-of-the-string-drawed-over-drawing-bitmap-in-net

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