ASP.NET 输出图片

获取指定路径中的图片的二进制数据,在页面中输出

using System.IO;

///指定被输出图像的地址

string path=Server.MapPath("~/images/aa.jpg");

///创建文件流,以读取图像

FileStream fs=new FileStream(path,FileMode.Open,FileAccess.Read);

///定义保存图像数据的二进制数组

byte[] Image=new byte[(int)fs.Length];

fs.Read(Image, 0, (int)fs.Length);

Response.Binary(Image);

///设置页面的输出格式,【注意】:在此只能输出jpg图片

Response.ContentType="image/pjpeg";

Response.End();

posted @ 2010-02-06 16:50  零纪录  阅读(1799)  评论(0编辑  收藏  举报