码迷,mamicode.com
首页 > Web开发 > 详细

【2017-6-9】WebForm 图片上传加水印

时间:2017-06-10 12:35:13      阅读:148      评论:0      收藏:0      [点我收藏+]

标签:event   eve   上传   后台   rgs   aws   webform   bsp   保存   

前台代码

<body>
    <form id="form1" runat="server">
    <div>
        <%--上传的控件--%>
        <asp:FileUpload ID="FileUpload1" runat="server" />
        <%--上传按钮--%>
        <asp:Button ID="Button1" runat="server" Text="上传" /><br />
        <%--提示是否验证成功--%>
        <asp:Image ID="Image1" runat="server" />
    </div>
    </form>
</body>

 

 

 

 

后台代码

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Drawing;

public partial class _Default : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        Button1.Click += Button1_Click;
    }

    void Button1_Click(object sender, EventArgs e)
    {
        //获得要上传的图片

        System.Drawing.Image img = System.Drawing.Image.FromStream(FileUpload1.FileContent);


        //加上水印
        Graphics g = Graphics.FromImage(img);
        string s = "WWW.ITNBA.COM";
        Font f = new Font("微软雅黑", 30);
        Brush b = new SolidBrush(Color.Red);
        PointF pf = new PointF(50, 50);
        //注意所需要的参数,在上面创建出来
        g.DrawString(s, f, b, pf);
        //保存下来

        string path = "Uploads/" + DateTime.Now.ToString("yyyyMMddhhmmssms") + FileUpload1.FileName;

        img.Save(Server.MapPath(path));
        Image1.ImageUrl = path;
    }
}

 

【2017-6-9】WebForm 图片上传加水印

标签:event   eve   上传   后台   rgs   aws   webform   bsp   保存   

原文地址:http://www.cnblogs.com/hanqi0216/p/6978121.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!