上代码:
//图片类型
Response.ContentType = "image/jpeg";
//元图路径
string filePath = Server.MapPath("ImgUpload/" + "9d82d158ccbf6c81db35544dbe3eb13533fa4010.jpg");
//水印内容
string addText = "localhost";
System.Drawing.Image image = System.Drawing.Image.FromFile(filePath);
Bitmap bitmap = new Bitmap(image.Width, image.Height);
System.Drawing.Graphics g = System.Drawing.Graphics.FromImage(bitmap);
g.DrawImage(image, 0, 0, image.Width, image.Height);
//字体
System.Drawing.Font f = new System.Drawing.Font("Arial Black", 30.0f, System.Drawing.FontStyle.Bold);
//笔刷色值
System.Drawing.Brush b = new System.Drawing.SolidBrush(System.Drawing.Color.Green);
//将原图画在位图上
g.DrawImage(image, new Point(0, 0));
//将水印加在位图上
g.DrawString(addText, f, b, new System.Drawing.PointF(50,50));
//将位图输入到流
bitmap.Save(Response.OutputStream, ImageFormat.Jpeg);
g.Dispose();
image.Dispose();
bitmap.Dispose();