[英]How can I set font height in system.drawings.font?
我正在使用C#以某种格式编写文本。 我的问题是,当我编辑字体大小时,宽度和高度都在改变,而我只想更改字体高度。
我的代码:
using (Graphics graphics = Graphics.FromImage(bitmap))
{
using (System.Drawing.Font romanfont = new System.Drawing.Font("Times New Roman",11, FontStyle.Bold))
//using (System.Drawing.Font romanfont = new System.Drawing.Font("Times New Roman", 11, FontStyle.Bold))
{
SolidBrush transBrush = new SolidBrush(Color.FromArgb(65, 79, 79));
StringFormat format = new StringFormat(StringFormatFlags.DirectionRightToLeft);
graphics.DrawString(firstname, romanfont, transBrush, firstnameLocation, format);
graphics.DrawString(secondname, romanfont, transBrush, secondnameLocation, format);
graphics.DrawString(finalfirstadd, romanfont, transBrush, firstaddresslocation, format);
graphics.DrawString(finalsecondadd, romanfont, transBrush, secondaddresslocation, format);
}
}
您可以通过在Graphics对象上设置转换来实现此效果。
例如,如果要使文本的高度加倍但宽度相同,则可以执行以下操作:
graphics.scaleTransform(1, 2);
您可以将其放在绘制线的位置上方的任何位置。 请注意,此更改将使所有内容变高两倍,因此您可能需要调整矩形的位置和大小(例如firstnameLocation
;在这种情况下,您可能希望将矩形的顶部和高度除以2。)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.