Font.Size上的Graphics.DrawString约束

时间:2013-11-15 10:11:52

标签: c# graphics

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}

0 个答案:

没有答案