实现代码:
/// <summary>
/// 给图片添加水印代码
/// by boxuming
/// </summary>
/// <returns></returns>
public Image AddWatermark(Image img)
{
//创建Graphic对象,核心的类
var myGraphic = Graphics.FromImage(img);
//水印内容
var sourceString = $"http://www.boxuming.com";
//水印字体
var font = new Font("Arial", 14);
//水印的尺寸
var size = myGraphic.MeasureString(sourceString, font);
//设置水印的属性:内容、字体、颜色、位置
myGraphic.DrawString(sourceString, font, System.Drawing.Brushes.WhiteSmoke,new PointF(img.Width - size.Width - 5, img.Height - size.Height - 5));
//释放myGraphic
myGraphic.Dispose();
return img;
}