C#给图片加水印的简单代码
发布时间:2020-12-15 17:55:10 所属栏目:百科 来源:网络整理
导读:今天PHP站长网 52php.cn把收集自互联网的代码分享给大家,仅供参考。 实现本网站图片保护功能? 类: using System;using System.Collections.Generic;using System.Linq;using System.Web;using System.Drawing;//image的
以下代码由PHP站长网 52php.cn收集自互联网 现在PHP站长网小编把它分享给大家,仅供参考
实现本网站图片保护功能?
类: 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> 以上内容由PHP站长网【52php.cn】收集整理供大家参考研究 如果以上内容对您有帮助,欢迎收藏、点赞、推荐、分享。 (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |