我确信您可能正在寻找这个。
rectf = new RectangleF(655, 460, 535, 90); //rectf for My Text
using(Graphics g = Graphics.FromImage(myBitmap))
{
//g.DrawRectangle(new Pen(Color.Red, 2), 655, 460, 535, 90);
g.SmoothingMode = SmoothingMode.AntiAlias;
g.InterpolationMode = InterpolationMode.HighQualityBicubic;
g.PixelOffsetMode = PixelOffsetMode.HighQuality;
StringFormat sf = new StringFormat();
sf.Alignment = StringAlignment.Center;
sf.LineAlignment = StringAlignment.Center;
g.DrawString("My\nText", new System.Drawing.Font("Tahoma", 32, FontStyle.Bold), Brushes.Black, rectf, sf);
}
//g.DrawRectangle(new Pen(Color.Red, 2), 655, 460, 535, 90);
线条用于显示文本将写入的位置。因此,在实际制作文本之前,您可以看到该矩形将在图像上的位置创建。如果你想要图像的中心,你可以找到高度和宽度,然后除以 2 来找到图像的中心,然后可以相应地绘制矩形参数。