asp. net Two Ways to Output Pictures in Binary Stream
- 2021-07-10 19:22:01
- OfStack
This paper describes two methods of asp. net to realize the output of pictures in binary stream. Share it for your reference, as follows:
Method 1:
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());
Method 2:
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();
I hope this article is helpful to everyone's asp. net programming.