asp.net读取二进制图片
// 将二进制数据转为物理文件
// byte[] data =(byte[])dt.Rows[0]["Head"]; //获取数据库中的图片流(image类型)
public void bytes2picFile(byte[] data)
{
string url = "images/" + DateTime.Now.ToString("yyyyMMddHHmmssffff") + ".jpg";
FileStream fs =new FileStream(Server.MapPath(url),System.IO.FileMode.Create);
fs.Write(data, 0, data.Length);
fs.Close();
this.Image1.ImageUrl = url;
}
//将文件转为二进制数据
public byte[] picFile2bytes(string picFilePath)
{
FileStream fs = new FileStream(picFilePath, FileMode.Open, FileAccess.Read);
byte[] bytePhoto = new byte[fs.Length];
fs.Read(bytePhoto, 0, (int)fs.Length);
fs.Close();
return bytePhoto;
}
// byte[] data =(byte[])dt.Rows[0]["Head"]; //获取数据库中的图片流(image类型)
public void bytes2picFile(byte[] data)
{
string url = "images/" + DateTime.Now.ToString("yyyyMMddHHmmssffff") + ".jpg";
FileStream fs =new FileStream(Server.MapPath(url),System.IO.FileMode.Create);
fs.Write(data, 0, data.Length);
fs.Close();
this.Image1.ImageUrl = url;
}
//将文件转为二进制数据
public byte[] picFile2bytes(string picFilePath)
{
FileStream fs = new FileStream(picFilePath, FileMode.Open, FileAccess.Read);
byte[] bytePhoto = new byte[fs.Length];
fs.Read(bytePhoto, 0, (int)fs.Length);
fs.Close();
return bytePhoto;
}