bitmap与byte[]之间相互转换

Bitmap   =>   byte[] 

Bitmap   b   =   new   Bitmap( "test.bmp "); 
 MemoryStream   ms   =   new   MemoryStream(); 
 b.Save(ms,System.Drawing.Imaging.ImageFormat.Bmp); 
 byte[]   bytes=   ms.GetBuffer();  //byte[]   bytes=   ms.ToArray(); 这两句都可以,至于区别么,下面有解释
ms.Close(); 

byte[]    =>   Bitmap

byte[]   bytelist=bytes; 
 MemoryStream   ms1   =   new   MemoryStream(bytelist); 
 Bitmap   bm   =   (Bitmap)Image.FromStream(ms1); 
 ms1.Close(); 
posted on 2024-09-13 15:04  侗家小蚁哥  阅读(4)  评论(0编辑  收藏  举报