asp.net中如何把字节流格式化为图片形式

2024-12-27 18:25:03
推荐回答(2个)
回答1:

using System.IO;
using System.Drawing.Imaging;
using System.Runtime.Serialization;
using System.Runtime.Serialization.Formatters.Binary;
-------------------------------------导包---------------------------

MemoryStream ms = new MemoryStream(); //创建一个内存流
image.Save(ms, ImageFormat.Jpeg); //把图片保存在内存流里面,格式为Jpeg格式
ms.Flush(); //关闭内存流
byte[] b=ms.GetBuffer(); //直接获得2进制byte数组
//b就是这个图片的字节流

回答2:

System.IO.MemoryStream s = new MemoryStream(字节数组);
System.Drawing.Bitmap bitmap = new System.Drawing.Bitmap(s);
bitmap.Save(filename);