COMM/picwater.cs
(开头部分) 2KB这里只显示每个文件的开头 60 行。登录后可以解锁完整代码。
using System;
using System.Web;
using System.Drawing;
using System.Drawing.Imaging;
/// <summary>
/// 说明:ImageHandler是一个图片处理类,它能实时在在图片上添加水印,避免自己网站的图片别的网站盗用
/// 作者:周公
/// 日期:2008-1-10
/// 首发地址:http://blog.csdn.net/zhoufoxcn
/// </summary>
public class ImageHandler : IHttpHandler
{
public ImageHandler()
{
//
// TODO: 在此处添加构造函数逻辑
//
}
#region IHttpHandler 成员
/// <summary>
/// 指示IHttpHandler 实例是否可再次使用
/// </summary>
public bool IsReusable
{
get { return true; }
}
/// <summary>
/// 处理请求的方法
/// </summary>
/// <param name="context">它提供对用于为 HTTP 请求提供服务的内部服务器对象(如 Request、Response、Session 和 Server)的引用。</param>
public void ProcessRequest(HttpContext context)
{
//获取请求的物理图片路径
string imagePath = context.Request.PhysicalPath;
Bitmap image = null;
if (context.Cache[imagePath] == null)//如果当前缓存中没有指定的图片就将该图片添加水印并缓存
{
image = new Bitmap(imagePath);
image = AddWaterMark(image);
context.Cache[imagePath] = image;
}
else//否则就直接从混存中取出添加了水印的图片,节省时间
{
image = context.Cache[imagePath] as Bitmap;
}
image.Save(context.Response.OutputStream, ImageFormat.Jpeg);//将添加水印的图片输入到当前流中
}
#endregion
//给图片添加水印
private Bitmap AddWaterMark(Bitmap image)
{
string text = System.Configuration.ConfigurationManager.AppSettings["WaterMark"].ToString();
int fontSize = int.Parse(System.Configuration.ConfigurationManager.AppSettings["Font-Size"].ToString());
Font font = new Font("宋体", fontSize,FontStyle.Bold);
//Brush brush = Brushes.DarkGray;
后面还有 8 行代码,购买后查看完整代码
24 小时内免费解锁 3 个项目,之后 1 算力/个。 规则说明
AI 解读 AI
登录后可用,每次 10 算力,解读结果公开显示在下面。
还没有人解读过这个文件。