/// <summary>
/// 将图片转换为二进制流
/// </summary>
/// <paramname="image"></param>
/// <returns></returns>
public static byte[]FormImageToByte(Image image)
{
MemoryStream ms = newMemoryStream();
image.Save(ms,System.Drawing.Imaging.ImageFormat.Jpeg);
return ms.GetBuffer();
}
/// <summary>
/// 将二进制流转换为图片
/// </summary>
/// <paramname="byteImage"></param>
/// <returns></returns>
public static ImageFormByteToImage(byte[] byteImage)
{
MemoryStream ms = newMemoryStream(byteImage);
return Image.FromStream(ms);
}
- 图片保存:
if(pictureEditphoto.Image == null)
{
_registerModel.PHOTO = newbyte[1];
}
else
{
_registerModel.PHOTO =CommonOperator.FormImageToByte(pictureEditphoto.Image);
}
- 图片显示:
if(model.PHOTO.Length == 1 && model.PHOTO[0] == 0)
{
pictureEditphoto.Image = null;
}
else
{
pictureEditphoto.Image =CommonOperator.FormByteToImage(model.PHOTO);
}