DotNet技术研究

  博客园 :: 首页 :: 博问 :: 闪存 :: 新随笔 :: 联系 :: 订阅 订阅 :: 管理 ::

     // 性能最高,其数组和像素一一对应   
        public static byte[] GetImgByte(this Bitmap bmp)
        {
            BitmapData bitmapData = bmp.LockBits(new System.Drawing.Rectangle(new Point(0, 0), bmp.Size),
                ImageLockMode.ReadWrite, PixelFormat.Format24bppRgb);
            byte[] res = new byte[bitmapData.Stride * bitmapData.Height];

            IntPtr Ptr = bitmapData.Scan0;
            System.Runtime.InteropServices.Marshal.Copy(Ptr, res, 0, res.Length);

            bmp.UnlockBits(bitmapData);
            return res;
        }

posted on 2011-03-08 14:05  <林海>  阅读(246)  评论(0编辑  收藏  举报