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


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

  


免責聲明!

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



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