byte[] image 互相转换
byte[] -> Image
Image -> byte[]
if(null != this.emp.Emp_Photo)
{
MemoryStream ms = new MemoryStream(this.emp.Emp_Photo);
if(ms.Length > 0)
{
this.picUsrPhoto.Image = Image.FromStream(ms);
}
else
{
this.picUsrPhoto.Image = null;
}
}
{
MemoryStream ms = new MemoryStream(this.emp.Emp_Photo);
if(ms.Length > 0)
{
this.picUsrPhoto.Image = Image.FromStream(ms);
}
else
{
this.picUsrPhoto.Image = null;
}
}
Image -> byte[]
Byte[] photo;
if(null != this.picUsrPhoto.Image)
{
MemoryStream ms = new MemoryStream();
this.picUsrPhoto.Image.Save(ms,System.Drawing.Imaging.ImageFormat.Jpeg);
photo = new Byte[ms.Length];
ms.Position = 0;
ms.Read(photo,0,Convert.ToInt32(ms.Length));
}
this.emp.Emp_Photo = photo;
if(null != this.picUsrPhoto.Image)
{
MemoryStream ms = new MemoryStream();
this.picUsrPhoto.Image.Save(ms,System.Drawing.Imaging.ImageFormat.Jpeg);
photo = new Byte[ms.Length];
ms.Position = 0;
ms.Read(photo,0,Convert.ToInt32(ms.Length));
}
this.emp.Emp_Photo = photo;