有没有办法以编程方式将文本添加到System.Drawing.Image?
问题描述:
我有一个用System.Drawing.Graphics DrawImage函数显示的System.Drawing.Image.该图像是警车,我想在警车上画一个单位编号.是否有捷径可寻?
I have a System.Drawing.Image that I display with System.Drawing.Graphics DrawImage function. The image is a police car, and I would like to draw a unit number on top of the police car. Is there an easy way to do this?
答
You can use the DrawString
method to write text out onto an image.
// Create string to draw.
String drawString = "Sample Text";
// Create font and brush.
Font drawFont = new Font("Arial", 16);
SolidBrush drawBrush = new SolidBrush(Color.Black);
// Create point for upper-left corner of drawing.
PointF drawPoint = new PointF(150.0F, 150.0F);
// Draw string to screen.
e.Graphics.DrawString(drawString, drawFont, drawBrush, drawPoint);