Asp.net(C#)给图片加上水印效果

 1if (FileUpload1.PostedFile.ContentType.ToLower().IndexOf("image"< 0)
 2        {
 3            FunctionUtility.JavaScriptHelper.Alert("上传的文件格式不正确!");
 4            return;
 5        }

 6
 7        Stream oStream = FileUpload1.PostedFile.InputStream;
 8        System.Drawing.Image oImage = System.Drawing.Image.FromStream(oStream);
 9
10        if(CheckBox1.Checked)
11        {
12            //加文字水印
13            Graphics g = Graphics.FromImage(oImage);
14            g.DrawImage(oImage, 00, oImage.Width, oImage.Height);
15            Font f = new Font("Verdana",15);
16            Brush b = new SolidBrush(Color.White);
17            g.DrawString("http://www.itwealth.cn制作", f, b, 0, oImage.Height - 30);
18            g.Dispose();
19        }

20        else
21        {
22            //加图片水印
23            System.Drawing.Image copyImage = System.Drawing.Image.FromFile(Server.MapPath("/DesignImages/Images/SYT/Admin.jpg"));
24            Graphics g = Graphics.FromImage(oImage);
25            g.DrawImage(copyImage, new Rectangle(oImage.Width - copyImage.Width, oImage.Height - copyImage.Height, copyImage.Width, copyImage.Height), 00, copyImage.Width, copyImage.Height, GraphicsUnit.Pixel);
26            g.Dispose();
27        }

28
29        string setFileName = FunctionUtility.FileHelper.GetDateTimeFileName() + ".jpg";
30        string oFullName = Server.MapPath("/DesignImages/Images/SYT/" + setFileName);
31        oImage.Save(oFullName, System.Drawing.Imaging.ImageFormat.Jpeg);
32        oImage.Dispose();
33
34        Image1.Visible = true;
35        Image1.ImageUrl = "/DesignImages/Images/SYT/" + setFileName;
36        FunctionUtility.JavaScriptHelper.Alert("水印加载成功!");

Tag标签: ASP.NET, 水印, 图片水印
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值