一个一维字节数组byte[]保存着 width*height 大小的8位图片灰度值,怎么把它转换成图片显示在picturebox里

解决方案 »

  1.   


    //byte[] 转图片  
    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();  
                }  
            }   
      
    //图片转byte[]   
            public static byte[] BitmapToBytes(Bitmap Bitmap)  
            {  
                MemoryStream ms = null;  
                try  
                {  
                    ms = new MemoryStream();  
                    Bitmap.Save(ms, Bitmap.RawFormat);  
                    byte[] byteImage = new Byte[ms.Length];  
                    byteImage = ms.ToArray();  
                    return byteImage;  
                }  
                catch (ArgumentNullException ex)  
                {  
                    throw ex;  
                }  
                finally  
                {  
                    ms.Close();  
                }  
            }  
        }