110,536
社区成员
发帖
与我相关
我的任务
分享
byte[] BitmapToBytes(Bitmap bmp)
{
MemoryStream ms=new MemoryStream();
bmp.Save(ms,System.Drawing.Imaging.ImageFormat.Jpeg);
ms.Close();
return ms.ToArray();
}
Bitmap BytesToBitmap(byte[] bytes)
{
MemoryStream ms=new MemoryStream(bytes);
Bitmap bmp=new Bitmap(ms);
ms.Close();
return bmp;
}
Image aa = new Bitmap(@"E:\photo\tm.jpg");
System.IO.MemoryStream stream = new System.IO.MemoryStream();
System.Runtime.Serialization.Formatters.Binary.BinaryFormatter formatter = new System.Runtime.Serialization.Formatters.Binary.BinaryFormatter();
formatter.Serialize(stream, aa); //将图像序列化成二进制流
stream.Position = 0;
Image bb = (Image)formatter.Deserialize(stream); //将二进制流序列成Image
this.pictureBox1.Image = bb;