Graphics.MeasureString允许太多空格 [英] Graphics.MeasureString allowing too much whitespace

查看:42
本文介绍了Graphics.MeasureString允许太多空格的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用一个函数来调用要在一个区域内呈现的一段文本.该功能的基本工作是:

I'm using a function to call for a piece of text to be rendered within an area. The basic working of the function is:

Dim measureSize as Size
Do
    myFont = new Font(myFont.Name, myFont.Size - 1, FontStyle.Regular, GraphicsUnit.Document)
    'Initial font size is set insanely high for the moment, during testing.
    'Low initial font size is not the problem.
    measureSize = g.MeasureString(myString, myFont)
Loop until (measuredSize.width < desiredSize.width AND measuredSize.height < desiredSize.height)

问题是MeasureString在它绘制的字符串周围添加了很多空白,并且最终的字体渲染得太小了.

The problem with this is that MeasureString is adding a lot of whitespace around the string it is drawing, and the final font is being rendered far too small.

我确定我记得有人可以摆弄一些参数以删除MeasureString方法中的所有填充,但是我的搜索目前没有任何作用.

I'm sure I remember some argument one can fiddle with in order to remove all the padding from the MeasureString method, but my searches currently aren't turning up anything.

有人知道如何使用MeasureString来测量字符串的精确大小,而没有任何边界吗?

Does anyone know how to use MeasureString to measure the EXACT size of the string without any bordering at all?

推荐答案

StringFormat.GenericTypographic 传递给 MeasureString .我建议不要使用TextRenderer,因为它在渲染到内存中的位图时会出现清晰类型的问题.

Pass StringFormat.GenericTypographic to MeasureString. I recommend against TextRenderer because it has problems with clear-type when rendering to an in-memory bitmap.

无疑,早晚使用TextRenderer进行度量,而使用DrawString进行绘制无疑会导致不一致.

Using TextRenderer for measurement and DrawString for drawing will undoubtedly get you into an inconsistency sooner or later.

这篇关于Graphics.MeasureString允许太多空格的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆