图片与二进制的相互转换
/// <summary>
/// 图片转成二进制
/// </summary>
/// <param name="UpFile"></param>
/// <returns></returns>
public static byte[] imageWrite(HttpPostedFile UpFile)
{
int FileLength = UpFile.ContentLength; //记录文件长度
if (FileLength == 0)
{ //文件长度为零时
return null;
}
else
{
Byte[] FileByteArray = new Byte[FileLength]; //图象文件临时储存Byte数组
Stream StreamObject = UpFile.InputStream; //建立数据流对像
//读取图象文件数据,FileByteArray为数据储存体,0为数据指针位置、FileLnegth为数据长度
StreamObject.Read(FileByteArray, 0, FileLength);
return FileByteArray;
}
}
/// <summary>
/// 二进制转成图片
/// </summary>
/// <param name="imageBtye"></param>
/// <returns></returns>
public static System.Drawing.Image imageRead(byte[] imageBtye)
{
System.IO.MemoryStream ms = new System.IO.MemoryStream(imageBtye);
System.Drawing.Image img = System.Drawing.Image.FromStream(ms);
return img;
}