日期:2014-05-18 浏览次数:20794 次
private void button1_Click( object sender, EventArgs e) { Bitmap b = pictureBox1.Image as Bitmap; int width = b.Width; int height = b.Height; BitmapData bd = b.LockBits ( new Rectangle( 0, 0, width, height), ImageLockMode.ReadOnly, PixelFormat.Format24bppRgb ); IntPtr imgPtr = bd.Scan0; int stride = bd.Stride; int widthByte = width*3; int skipByte = stride - widthByte; int [,,] rgbData = new int [width,height,3 ]; #region 讀取 RGB 資料 unsafe { byte* p = ( byte*) ( void*) imgPtr; for ( int j = 0; j < height; j++) { for ( int i = 0; i < width; i++) { rgbData[i, j, 2 ] = p[ 0 ]; p++; rgbData[i, j, 0 ] = p[ 0 ]; p++; rgbData[i, j, 1 ] = p[ 0 ]; p++; } p += skipByte; } } #endregion