public Bitmap AddString(Bitmap bitmap, string str)
{
using (Graphics g = Graphics.FromImage(bitmap))
{
SolidBrush recbrush = new SolidBrush(Color.FromArgb(255, 0, 0, 0)); //水印背景颜色,透明度
Brush fontBrush = new SolidBrush(Color.FromArgb(255, 255, 255, 255)); //字体颜色
RectangleF rectangle = new RectangleF();
using (Font font = new Font("Arial", 48, FontStyle.Bold))
{
rectangle.Location = new Point(0, 100); 水印位置
rectangle.Size = new Size(bitmap.Width, ((int)g.MeasureString(str, font, bitmap.Width, StringFormat.GenericTypographic).Height)); //根据水印长短自动换行
g.FillRectangle(recbrush, rectangle);
g.DrawString(str, font, fontBrush, rectangle);
}
return bitmap;
}
}