c# 中怎么把image转换为byte[]

怎么把image类型转换为byte[]数据流类型请写点具体代码,谢谢
2024-12-26 08:27:31
推荐回答(2个)
回答1:

System.IO.MemoryStream Ms = new MemoryStream();
this.pcbEquipment.Image.Save(Ms, System.Drawing.Imaging.ImageFormat.Jpeg);
byte[] img = new byte[Ms.Length];
Ms.Position = 0;
Ms.Read(img, 0, Convert.ToInt32(Ms.Length));
Ms.Close();

回答2:

image.save存为流.再把流转为byte数组

Image img = Image.FromFile("c:\\00.jpg");
MemoryStream ms = new MemoryStream();
img.Save(ms, ImageFormat.Jpeg);
byte[] bytes = new byte[ms.Length];
ms.Write(bytes, 0,(int) ms.Length);