將byte數組保存成圖片:數組
方式一:System.IO.File.WriteAllBytes(
@"c:\test.jpg"
, bytes);
this
方式二:MemoryStream ms=new MemoryStream(Byte[] b); 把那個byte[]數組傳進去,而後
FileStream fs=new FileStream(路徑 例如:"E:\image\1.jpg");
ms.writeto(fs);
ms.close();
fs.close();spa
方法三:code
//獲得圖片地址
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();
}