本文实例讲述了asp.net实现图片以二进制流输出的两种方法。分享给大家供大家参考,具体如下:

方法一:

System.IO.MemoryStream ms = new System.IO.MemoryStream();
System.IO.Stream str = new FileUpload().PostedFile.InputStream;
System.Drawing.Bitmap map = new System.Drawing.Bitmap(str);
map.Save(ms, System.Drawing.Imaging.ImageFormat.Gif);
Response.ClearContent();
Response.ContentType = "image/gif";
Response.BinaryWrite(ms.ToArray());

方法二:

System.IO.FileStream fs = new System.IO.FileStream("Filename", System.IO.FileMode.Open, System.IO.FileAccess.Read);
byte[] datas = new byte[fs.Length];
fs.Read(datas, 0, Convert.ToInt32(fs.Length));
fs.Close();
Response.OutputStream.Write(datas,0,Convert.ToInt32(fs.Length));
Response.End();

希望本文所述对大家asp.net程序设计有所帮助。

点赞(0)

微信公众账号

微信扫一扫加关注

发表
评论
返回
顶部