当前位置: 编程技术>.net/c#/asp.net
C# 图片与二进制转换的简单实例
来源: 互联网 发布时间:2014-10-23
本文导语: 代码如下:///图片转二进制private byte[] convertByte(Image img){ MemoryStream ms = new MemoryStream(); img.Save(ms, img.RawFormat); //byte[] bytes = new byte[ms.Length]; //ms.Read(bytes, 0, Convert.ToInt32(ms.Length)); //以上两句改成下面两句 b...
代码如下:
///图片转二进制
private byte[] convertByte(Image img)
{
MemoryStream ms = new MemoryStream();
img.Save(ms, img.RawFormat);
//byte[] bytes = new byte[ms.Length];
//ms.Read(bytes, 0, Convert.ToInt32(ms.Length));
//以上两句改成下面两句
byte[] bytes = ms.ToArray();
ms.Close();
return bytes;
}
///二进制生成图片
private Image convertImg(byte[] datas)
{
MemoryStream ms = new MemoryStream(datas);
Image img = Image.FromStream(ms, true);
ms.Close();
return img;
}