// Copyright (c) 2005 by Augmentum, Inc. // All Rights Reserved.using System; using System.IO; using System.Web; using System.Drawing; using System.Drawing.Imaging; using TrainingProject.Entity;namespace TrainingProject.BizLogic { /// <summary> /// Description of ImageHandler. /// </summary> public class ImageHandler : IHttpHandler { /// <summary> /// Deal with image /// </summary> /// <param name="context"></param> public void ProcessRequest(HttpContext context) { int productId = Convert.ToInt32(context.Request.QueryString["ProductID"]); ProductBiz productBiz = new ProductBiz(); Product product = productBiz.GetProductByID(productId); if(product.Picture.Length > 0) { context.Response.Clear(); context.Response.AddHeader("Content-Type","application/octet-stream"); context.Response.BinaryWrite(product.Picture); } else { Bitmap blankPic = new Bitmap(100,50); Graphics g = Graphics.FromImage(blankPic); g.Clear(Color.Gray); Font textFont = new Font("Comic Sans MS", 10); g.DrawString("No picture.", textFont, Brushes.Aqua, 15, 20); blankPic.Save(context.Response.OutputStream, ImageFormat.Jpeg); } }
/// <summary> /// Override the IsReusable property. /// </summary> public bool IsReusable { get { return true; } } } }
// All Rights Reserved.using System;
using System.IO;
using System.Web;
using System.Drawing;
using System.Drawing.Imaging;
using TrainingProject.Entity;namespace TrainingProject.BizLogic
{
/// <summary>
/// Description of ImageHandler.
/// </summary>
public class ImageHandler : IHttpHandler
{
/// <summary>
/// Deal with image
/// </summary>
/// <param name="context"></param>
public void ProcessRequest(HttpContext context)
{
int productId = Convert.ToInt32(context.Request.QueryString["ProductID"]);
ProductBiz productBiz = new ProductBiz();
Product product = productBiz.GetProductByID(productId);
if(product.Picture.Length > 0)
{
context.Response.Clear();
context.Response.AddHeader("Content-Type","application/octet-stream");
context.Response.BinaryWrite(product.Picture);
}
else
{
Bitmap blankPic = new Bitmap(100,50);
Graphics g = Graphics.FromImage(blankPic);
g.Clear(Color.Gray);
Font textFont = new Font("Comic Sans MS", 10);
g.DrawString("No picture.", textFont, Brushes.Aqua, 15, 20);
blankPic.Save(context.Response.OutputStream, ImageFormat.Jpeg);
}
}
/// <summary>
/// Override the IsReusable property.
/// </summary>
public bool IsReusable
{
get { return true; }
}
}
}