图片水印

引命名空间using System.Drawing; 

文字水印:

System.Drawing.Image img = System.Drawing.Image.FromStream(FileUpload1.FileContent);
Graphics gr = Graphics.FromImage(img);
string s = "段誉";
Font f = new Font("微软雅黑", 50);
Brush b = new SolidBrush(Color.Aqua);
PointF p = new PointF(img.Width - 200, img.Height - 100);
gr.DrawString(s, f, b, p);
img.Save(Server.MapPath("ul/" + DateTime.Now.ToString("yyyyMMddHHmmssms") + FileUpload1.FileName));
Image1.ImageUrl = "ul/" + DateTime.Now.ToString("yyyyMMddHHmmssms") + FileUpload1.FileName;

图片水印:

System.Drawing.Image img = System.Drawing.Image.FromStream(FileUpload1.FileContent);
System.Drawing.Image logo = System.Drawing.Image.FromFile(Server.MapPath("ul/111.PNG"));
Graphics gr = Graphics.FromImage(img);
PointF p = new PointF(50, 50);
gr.DrawImage(logo, p);
img.Save(Server.MapPath("ul/" + DateTime.Now.ToString("yyyyMMddHHmmssms") + FileUpload1.FileName));
Image1.ImageUrl = "ul/" + DateTime.Now.ToString("yyyyMMddHHmmssms") + FileUpload1.FileName;

 PointF与Point一样!

posted on 2018-01-14 16:24  段了的弦  阅读(157)  评论(0编辑  收藏  举报