实现本网站图片保护功能之加水印

类: 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>

posted @ 2013-01-02 16:23  SevenNiu  阅读(369)  评论(0编辑  收藏  举报