/// <summary>
/// ImageData 的摘要说明
/// </summary>
public class ImageData : IHttpHandler
{ public void ProcessRequest(HttpContext context)
{
context.Response.ContentType = "image/Jpeg";
string item_code = context.Request.QueryString["ItemCode"];
IntegralDal dal = new IntegralDal();
byte[] imgbyte = dal.GetImage(item_code);
Bitmap myImage = new Bitmap(GetImageByBytes(imgbyte));
MemoryStream ms = new MemoryStream();
myImage.Save(ms, System.Drawing.Imaging.ImageFormat.Jpeg);
context.Response.ClearContent();
ms.WriteTo(context.Response.OutputStream);
context.Response.Flush();
context.Response.End();
} }
/// <summary>
/// 读取byte[]并转化为图片
/// </summary>
/// <param name="bytes">byte[]</param>
/// <returns>Image</returns>
public static Image GetImageByBytes(byte[] bytes)
{
Image photo = null;
using (MemoryStream ms = new MemoryStream(bytes))
{
ms.Write(bytes, , bytes.Length);
photo = Image.FromStream(ms, true);
} return photo;
}
实现:
this.image.Src = " ../Servers/ImageData.ashx?ItemCode=" + model.ItemCode;