1.将Image转换成byte[]
1 public byte[] ImageToByteArray(Image image) 2 { 3 MemoryStream imageStream = new MemoryStream(); 4 image.Save(imageStream, System.Drawing.Imaging.ImageFormat.Jpeg); 5 byte[] imageContent = new Byte[imageStream.Length]; 6 imageStream.Position = 0; 7 imageStream.Read(imageContent, 0, (int)imageStream.Length); 8 return imageStream.ToArray(); 9 }
2.将byte[]Image转换成Image
1 public Image ByteToImage(byte[] byteImage) 2 { 3 MemoryStream stream = null; 4 try 5 { 6 stream = new MemoryStream(byteImage); 7 Image bitmapnew = ((Image)new Bitmap(stream)); 8 return bitmapnew; 9 } 10 catch (ArgumentNullException ex) 11 { 12 throw ex; 13 } 14 catch (ArgumentException ex) 15 { 16 throw ex; 17 } 18 finally 19 { 20 stream.Close(); 21 } 22 }
原文:https://www.cnblogs.com/yellow3gold/p/14419427.html