Response.BinaryWrite()方法輸出二進制圖像


 1         protected void Page_Load(object sender, EventArgs e)
 2         {
 3             FileStream fs = new FileStream(Server.MapPath("未命名.jpg"), FileMode.Open);//將圖片文件存在文件流中
 4             long fslength = fs.Length;//流長度
 5             byte[] b=new byte[(int)fslength];//定義二進制數組
 6             fs.Read(b, 0, (int)fslength);//將流中字節寫入二進制數組中
 7             fs.Close();//關閉流
 8             Response.ContentType = "image/jpg";//沒有這個會出現亂碼
 9             Response.BinaryWrite(b);//將圖片輸出在頁面
10         }

Response.BinaryWrite()不能與Response.Write()一起使用。


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM