实现本网站图片保护功能之加水印
類: using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Drawing;//image的命名空間
namespace 實現本網站圖片保護功能 { ??? 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做為填充他的參數 ??????????? 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:從緩存區中輸出 ??????????? context.Response.End();//6:結束 ??????????? //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="實現本網站圖片保護功能.yanzhengma"/><!--第一個屬性verb是處理什么樣的文件,path是處理那個文件夾下的圖片,type是要配置的文件類--> ??????? ????? </httpHandlers>
轉載于:https://www.cnblogs.com/ngy7/archive/2013/01/02/2842208.html
總結
以上是生活随笔為你收集整理的实现本网站图片保护功能之加水印的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: Notepad++ 插件之 TextFX
- 下一篇: UITabbarController