c# Bitmap byte[]互转

来源:互联网 发布:火影忍者挂机软件 编辑:程序博客网 时间:2024/05/16 15:01

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(); } } 



0 0
原创粉丝点击