0

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}
4

0 回答 0