WebForm 【上传图片--添加水印】
对图片添加水印,上传
<div> <asp:FileUpload ID="FileUpload1" runat="server" /> <asp:Button ID="Button1" runat="server" Text="上传" /><br /> <asp:Image ID="Image1" runat="server" /> </div>
protected void Page_Load(object sender, EventArgs e) { Button1.Click += Button1_Click; } void Button1_Click(object sender, EventArgs e) { //1、制作画布 System.Drawing.Image img = System.Drawing.Image.FromStream(FileUpload1.FileContent); Graphics g = Graphics.FromImage(img); //水印样式:画什么东西 string a = "http://www.itnba.com"; //字体、大小 Font f = new Font("黑体", 30); //颜色 Brush b = new SolidBrush(Color.Red); //0,0——开始画水印的位置 g.DrawString(a, f, b, 0, 0); //保存路径 string path = "images/" + FileUpload1.FileName; img.Save(Server.MapPath(path)); //在image控件中展示 Image1.ImageUrl = path; }