日期:2014-05-18 浏览次数:21046 次
Rectangle rect = myrect;//要处理的矩形区域
            if (bmpImg != null)//如果图片不为null。Bitmap bmpImg
            {
                System.Drawing.Imaging.BitmapData bmpData = bmpImg.LockBits(rect, System.Drawing.Imaging.ImageLockMode.ReadWrite, bmpImg.PixelFormat);
                byte temp = 0;
                bmpHeight = rect.Height;
                bmpWidth = rect.Width;
                rgbValue = new byte[bmpHeight, bmpWidth];
                unsafe
                {
                    byte* ptr = (byte*)(bmpData.Scan0);
                    for (int i = 0; i < bmpHeight; i++)//高度
                    {
                        for (int j = 0; j < bmpWidth; j++)//宽度
                        {
                            temp = ptr[0];  //bgr排列
                            ptr += 1;
                            rgbValue[i, j] = temp;//当前选择的图像每一点的灰度值
                        }
/*重点是这里, 这句话我寻思了好久都没明白是什么意思。  求解. 明白是什么意思的朋友帮忙解释一下 哈~谢啦*/
                        ptr += bmpData.Stride - bmpWidth;
                    }
                }
                bmpImg.UnlockBits(bmpData);
            }