songguo 通过本文主要向大家介绍了c#给图片加水印,c#图片加水印,c#水印,c#图片水印,c#textbox水印等相关知识,希望对您有所帮助,也希望大家支持linkedu.com www.linkedu.com
本文实例讲述了C#给图片加水印的简单实现方法。分享给大家供大家参考。具体分析如下:
这里实现本网站图片保护功能类:
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:配置
}
}
}
</div>
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></div>
配置:
<httpHandlers> <add verb="*" path="imgs/*.jpg" type="实现本网站图片保护功能.yanzhengma"/> <!--第一个属性verb是处理什么样的文件,path是处理那个文件夹下的图片, type是要配置的文件类--> </httpHandlers></div>
希望本文所述对大家的C#程序设计有所帮助。
</div>
