How to scale text when drawing to an Image with c#
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.
精彩评论