C#給圖片加水印的簡單實現(xiàn)方法
更新時間:2015年05月04日 11:33:23 作者:songguo
這篇文章主要介紹了C#給圖片加水印的簡單實現(xiàn)方法,涉及C#操作圖片的相關(guān)技巧,非常具有實用價值,需要的朋友可以參考下
本文實例講述了C#給圖片加水印的簡單實現(xiàn)方法。分享給大家供大家參考。具體分析如下:
這里實現(xiàn)本網(wǎng)站圖片保護功能類:
using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Drawing;//image的命名空間 namespace 實現(xiàn)本網(wǎng)站圖片保護功能 { public class yanzhengma:IHttpHandler { public bool IsReusable { get { throw new NotImplementedException(); } } public void ProcessRequest(HttpContext context) //請求的方法 { Image img = Image.FromFile(context.Request.PhysicalPath); //1:從文件中獲取圖片;獲取請求的文件的物理路徑 Graphics g = Graphics.FromImage(img); //2:聲明graphicse把img做為填充他的參數(shù) g.DrawString("net",new Font("宋體",20,FontStyle.Italic),Brushes.Blue,10,10); //3:在graphicse上寫圖片 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="實現(xiàn)本網(wǎng)站圖片保護功能.yanzhengma"/> <!--第一個屬性verb是處理什么樣的文件,path是處理那個文件夾下的圖片, type是要配置的文件類--> </httpHandlers>
希望本文所述對大家的C#程序設(shè)計有所幫助。
相關(guān)文章
C#導(dǎo)出Excel的幾種常見方式及詳細(xì)實現(xiàn)步驟
excel導(dǎo)出在C#代碼中應(yīng)用己經(jīng)很廣泛了,我這里就做些總結(jié),下面這篇文章主要給大家介紹了關(guān)于C#導(dǎo)出Excel的幾種常見方式及詳細(xì)實現(xiàn)步驟的相關(guān)資料,文中通過實例代碼介紹的非常詳細(xì),需要的朋友可以參考下2023-06-06C#實現(xiàn)功能強大的中國農(nóng)歷日歷操作類
這篇文章主要介紹了C#實現(xiàn)功能強大的中國農(nóng)歷日歷操作類,實例分析了C#操作時間及字符串的技巧,非常具有實用價值,需要的朋友可以參考下2015-03-03