using System;
using System.Data;
using System.Configuration;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Drawing;
using System.IO;
/// <summary>
///waterH 的摘要说明
/// </summary>
public class waterH:IHttpHandler
{
public waterH()
{}
private const string WATERMARK_URL = "~/Images/Watermark.png";
private const string DEFAULTIMAGE_URL = "~/images/blank.gif";
public void ProcessRequest(HttpContext context)
{
System.Drawing.Image Cover;
if (File.Exists(context.Request.PhysicalPath))
{
Cover = Image.FromFile(context.Request.PhysicalPath);
Image watermark = Image.FromFile(context.Request.MapPath(WATERMARK_URL));
Graphics g = Graphics.FromImage(Cover);
g.DrawImage(watermark, new Rectangle(Cover.Width - watermark.Width, Cover.Height - watermark.Height, watermark.Width, watermark.Height), 0, 0, watermark.Width, watermark.Height, GraphicsUnit.Pixel);
g.Dispose();
watermark.Dispose();
}
else
{
Cover = Image.FromFile(context.Request.MapPath(DEFAULTIMAGE_URL));
}
context.Response.ContentType = "images/jpeg";
Cover.Save(context.Response.OutputStream, System.Drawing.Imaging.ImageFormat.Jpeg);
Cover.Dispose();
context.Response.End();
}
public bool IsReusable
{
get
{
return false;
}
}
}