中文字幕在线观看,亚洲а∨天堂久久精品9966,亚洲成a人片在线观看你懂的,亚洲av成人片无码网站,亚洲国产精品无码久久久五月天

C#給圖片加水印的簡(jiǎn)單代碼

2018-07-20    來(lái)源:open-open

容器云強(qiáng)勢(shì)上線!快速搭建集群,上萬(wàn)Linux鏡像隨意使用
實(shí)現(xiàn)本網(wǎng)站圖片保護(hù)功能 
類:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Drawing;//image的命名空間
namespace 實(shí)現(xiàn)本網(wǎng)站圖片保護(hù)功能
{
    public class yanzhengma:IHttpHandler
    {
        public bool IsReusable
        {
            get { throw new NotImplementedException(); }
        }
        public void ProcessRequest(HttpContext context)//請(qǐng)求的方法
        {
            Image img = Image.FromFile(context.Request.PhysicalPath);//1:從文件中獲取圖片;獲取請(qǐng)求的文件的物理路徑
            Graphics g = Graphics.FromImage(img); //2:聲明graphicse把img做為填充他的參數(shù)
            g.DrawString("net", new Font("宋體", 20, FontStyle.Italic), Brushes.Blue, 10, 10);//3:在graphicse上寫(xiě)圖片
            img.Save(context.Response.OutputStream,System.Drawing.Imaging.ImageFormat.Jpeg);//4:保存(保存到什么什么流里,什么格式保存)
            context.Response.Flush();//5:從緩存區(qū)中輸出
            context.Response.End();//6:結(jié)束
            //7:配置
        }
    }
}

webform1.aspx:
<div>
       <%-- <asp:GridView ID="GridView1" runat="server">
        </asp:GridView>
        <asp:SqlDataSource ID="SqlDataSource1" runat="server"></asp:SqlDataSource>--%>
        <asp:Image ID="Image1" runat="server" imageurl="imgs/1.jpg"/>
        <%--<image src="http://localhost:2309/WebForm1.aspx"></image>--%>
    </div>
配置:
<httpHandlers>
        <add verb="*" path="imgs/*.jpg" type="實(shí)現(xiàn)本網(wǎng)站圖片保護(hù)功能.yanzhengma"/><!--第一個(gè)屬性verb是處理什么樣的文件,path是處理那個(gè)文件夾下的圖片,type是要配置的文件類-->
        
      </httpHandlers>

標(biāo)簽:

版權(quán)申明:本站文章部分自網(wǎng)絡(luò),如有侵權(quán),請(qǐng)聯(lián)系:west999com@outlook.com
特別注意:本站所有轉(zhuǎn)載文章言論不代表本站觀點(diǎn)!
本站所提供的圖片等素材,版權(quán)歸原作者所有,如需使用,請(qǐng)與原作者聯(lián)系。

上一篇:C#監(jiān)控文件或目錄的變化

下一篇:C#二分查找算法演示代碼