日期:2014-05-20 浏览次数:20908 次
private static Byte[] ConvertImageToByte(Image image)
{
//图片转换为二进制数组begin
MemoryStream mstream = new MemoryStream();
image.Save(mstream, System.Drawing.Imaging.ImageFormat.Jpeg);
Byte[] ImageByte = new Byte[(int)mstream.Length];
ImageByte = mstream.GetBuffer();
//mstream.Read(ImageByte, 0, ImageByte.Length);//这种错误了 mstream.Close();
//end
return ImageByte;
}
private Image ConvertImageByByte(byte[] buffer)
{
if (buffer != null)
{
MemoryStream ms = new MemoryStream(buffer);
try
{
Image img = System.Drawing.Image.FromStream(ms);
ms.Close();
return img;
}
catch (Exception ex)
{
return null;
}
finally
{
ms.Close();
}
}
else
{
return null;
}
}