使用 C# 绘制图像时如何缩放文本
我想在一个矩形中绘制一些文本,并将其缩放到适合矩形的最大尺寸。
到目前为止,我有这个:
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");
它绘制文本但不放大字体大小。
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
在二分搜索循环中调用 Graphics.MeasureString。
Call Graphics.MeasureString in a binary search loop.