原文链接:http://www.cnblogs.com/zz-930474270/p/6046033.html
将byte数组保存成图片:
方式一:System.IO.File.WriteAllBytes(
@"c:\test.jpg"
, bytes);
方式二:MemoryStream ms=new MemoryStream(Byte[] b); 把那个byte[]数组传进去,然后
FileStream fs=new FileStream(路径 例如:"E:\image\1.jpg");
ms.writeto(fs);
ms.close();
fs.close();
方法三:
//得到图片地址 var stringFilePath = context.Server.MapPath(string.Format("~/Image/{0}{1}.jpg", imageName, id)); //声明一个FileStream用来将图片暂时放入流中 FileStream stream = new FileStream(stringFilePath, FileMode.Open); using (stream) { //透过GetImageFromStream方法将图片放入byte数组中 byte[] imageBytes = this.GetImageFromStream(stream,context); //上下文确定写到客户短时的文件类型 context.Response.ContentType = "image/jpeg"; //上下文将imageBytes中的数据写到前段 context.Response.BinaryWrite(imageBytes); stream.Close(); }