//Byte[] result;
System.IO.MemoryStream ms =new MemoryStream(result, 0, result.Length)
Response.ClearContent();
Response.ContentType = "image/Gif";
Response.BinaryWrite(ms.ToArray());
或者添加一个处理图片的Handler,内容如下:
<%@ WebHandler Language="C#" Class="Handler" %>
using System.Web;
using System.IO;
public class Handler : IHttpHandler {
public void ProcessRequest (HttpContext context) {
int CategoryID = int.Parse(context.Request.QueryString["CategoryID"]);
//调用Categories.GetPicture取得图片stream
Stream stream = CategoriesPicture.GetPicture(CategoryID);
if (stream !=null) {
//取得图片stream大小
int buffersize = (int)stream.Length;
//建立buffer
System.Byte[] buffer = new System.Byte[buffersize ] ;
//调用stream.Read,从stream读取到buffer,并返回count
int count = stream.Read(buffer, 0, buffersize);
//返回图片字段buffer
if (count!=0)
context.Response.OutputStream.Write(buffer, 0, count);
}
}
public bool IsReusable {
get {
return false;
}
}
}
直接写个ashx然后Response.BinaryWrite(bytes)不就行了么
通过动态页面中转
<img src="myImageReader.aspx?imageId=1"/>
其中 myImageReader.aspx 的后台代码大致为:
Response.clear();
Response.ContentType="jpeg/img";//?
byte[] bytes = SelectFromDatabaseById(imageId);//?
Response.BinaryWrite(bytes)
Response.End();
我从前是在图片放到数据库中,或许不适合你的场景。