开发者

How to scale text when drawing to an Image with c#

开发者 https://www.devze.com 2023-01-31 22:34 出处:网络
I would like开发者_运维知识库 to draw some text in a rectangle and have it scale to the maximum size that fits within the rectangle.

I would like开发者_运维知识库 to draw some text in a rectangle and have it scale to the maximum size that fits within the rectangle.

So far I have this:

    Bitmap bitmapImage = new Bitmap(500, 500);
    Graphics graphicImage = Graphics.FromImage(bitmapImage); 
    graphicImage.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.AntiAlias;

    var rect = new Rectangle(0, 0, 500, 500);

    graphicImage.DrawString( "testing testing 123!", new Font("Arial", 12, FontStyle.Bold), Brushes.Black, rect);               
    bitmapImage.Save("test.png");       

it draws the text but doesn't scale up the font size.


Call Graphics.MeasureString in a binary search loop.

0

精彩评论

暂无评论...
验证码 换一张
取 消