一、图片与字节数组互转
private void Test() { string picPath = @"C:\Users\Public\Pictures\Sample Pictures\Cat.jpg"; byte[] photo = ImageToByte(picPath); pictureBox1.Image = ByteToImage(photo); pictureBox1.SizeMode = PictureBoxSizeMode.Zoom; pictureBox1.BackgroundImageLayout = ImageLayout.Zoom; } private byte[] ImageToByte(string path) { byte[] photo; Image img = new Bitmap(path); MemoryStream stream = new MemoryStream(); img.Save(stream, System.Drawing.Imaging.ImageFormat.Bmp); photo = stream.ToArray(); stream.Close(); return photo; } private Image ByteToImage(byte[] photo) { MemoryStream ms = new MemoryStream(photo, true); Image img1 = Image.FromStream(ms); return img1; }
标签:MemoryStream,stream,C#,photo,Image,汇总,private,byte,图片 From: https://www.cnblogs.com/Mars-0603/p/17705542.html