将图片转换成二进制流:
public static byte[] GetBytesByImagePath(string strFile)
{
byte[] photo_byte = null;
using (FileStream fs = new FileStream(strFile, FileMode.Open, FileAccess.Read))
{
using (BinaryReader br = new BinaryReader(fs))
{
photo_byte = br.ReadBytes((int)fs.Length);
br.Close();
}
fs.Dispose();
}
return photo_byte;
}
将二进制流转换为图片
public static Image GetImageByByte(byte [] bytes)//将二进制流转换为图片;
{
Image photo=null;
using(MemoryStream ms=new MemoryStream(bytes))
{
ms.Write(bytes, 0, bytes.Length);
photo = Image.FromStream(ms, true);
ms.Dispose();
}
return photo;
}