图片流
先做一个输出图片的网页
1 public partial class ShowImg : System.Web.UI.Page 2 { 3 private string file = string.Empty; 4 protected void Page_Load(object sender, EventArgs e) 5 { 6 //获取文件的地址参数 7 file = Request.QueryString["file"].ToString(); 8 //以数据流的形式根据文件地址打开文件 9 FileStream stream = new FileStream(file, FileMode.Open); 10 //Get Size of the file 11 long FileSize = stream.Length; 12 //定义一个二进制数据 13 byte[] Buffer=new byte[(int)FileSize]; 14 stream.Read(Buffer, 0, (int)FileSize); 15 stream.Close(); 16 Response.BinaryWrite(Buffer); 17 stream = null; 18 } 19 }
使用方法如下:
前台:<img id="img1" runat="Server" />
后台:img1.Src = "ShowImg.aspx?file=" + Server.UrlEncode(@"F:\图标素材\3960\chat.png");
我是一个小小虫
用编程改变世界