public class PicHandler : IHttpHandler {
private const string COVERSADDR = "~/Image/BookCovers/";
private const string WATERMARK_URL = "~/Image/WaterMark.jpg";
private const string DEFAULT_URL = "~/Image/default.jpg";
public void ProcessRequest(HttpContext context) {
/// string path = context.Request.MapPath(COVERSADDR + context.Request.Params["ISBN"].ToString() + ".jpg");
if (File.Exists(context.Request.PhysicalPath)) {
Image 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);
Cover.Save(context.Response.OutputStream, System.Drawing.Imaging.ImageFormat.Jpeg);
context.Response.ContentType = "image/jpeg";
g.Dispose();
watermark.Dispose();
}
else {
Image c = Image.FromFile(context.Request.MapPath(DEFAULT_URL));
c.Save(context.Response.OutputStream, System.Drawing.Imaging.ImageFormat.Jpeg);
context.Response.ContentType = "image/jpeg";
}
}