【2017-6-9】WebForm 圖片上傳加浮水印

來源:互聯網
上載者:User

標籤: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 圖片上傳加浮水印

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.