c# Bitmap byte[]互转
c# Bitmap转byte[]
转自:http://www.cnblogs.com/liuxinls/p/3365276.html
public static byte[] Bitmap2Byte(Bitmap bitmap) { using (MemoryStream stream = new MemoryStream()) { bitmap.Save(stream , ImageFormat.Jpeg); byte[] data = new byte[stream.Length]; stream.Seek(0 , SeekOrigin.Begin); stream.Read(data ,0 , Convert.ToInt32(stream.Length)); return data; } }
byte[] 转换 Bitmap
public static Bitmap BytesToBitmap(byte[] Bytes) { MemoryStream stream = null; try { stream = new MemoryStream(Bytes); return new Bitmap((Image)new Bitmap(stream)); } catch (ArgumentNullException ex) { throw ex; } catch (ArgumentException ex) { throw ex; } finally { stream.Close(); } }
声明:该文观点仅代表作者本人,入门客AI创业平台信息发布平台仅提供信息存储空间服务,如有疑问请联系rumenke@qq.com。