Font.Size
方法的Graphics.DrawString
是否有下限?
当我尝试为字符串的所有字符获取块时,出现此问题,使用Graphics.MeasureCharacterRanges
作为小字体。
示例代码:
Bitmap bitmap = new Bitmap(100, 100);
Graphics graphics = Graphics.FromImage(bitmap);
string text = "\\";
Font font = new Font("Arial", 1.5f);
RectangleF rectangle1 = new RectangleF(0, 0, 10, 10);
RectangleF rectangle2 = new RectangleF(0.1f, 0, 10, 10);
StringFormat stringFormat = new StringFormat(StringFormat.GenericDefault);
stringFormat.SetMeasurableCharacterRanges(new[] {new CharacterRange(0, 1)});
Region[] regions = graphics.MeasureCharacterRanges(text, font, rectangle1, stringFormat);
Console.Out.WriteLine(regions[0].GetBounds());
regions = graphics.MeasureCharacterRanges(text, font, rectangle2, stringFormat);
Console.Out.WriteLine(regions[0].GetBounds());
示例输出:
{X=0,Y=0,Width=1,Height=3}
{X=0,Y=0,Width=0,Height=0}