sxw888请进,这个怎么改?
// 锁住数据.
Rectangle rect = new Rectangle(0, 0, bitmap.Width, bitmap.Height);
System.Drawing.Imaging.BitmapData bitmapData =
bitmap.LockBits(rect, System.Drawing.Imaging.ImageLockMode.ReadWrite,
bitmap.PixelFormat);
IntPtr ptr = bitmapData.Scan0;
int bytes = bitmap.Width * bitmap.Height * 3;
byte[] rgbValues = new byte[bytes];
// 遍历数据.
//bitmap.Palette.Entries[y * bitmapData.Stride + x] //这个是灰度图像的定位方法
for (int x = 0; x < bitmap.Width; x++)
{
for (int y = 0; y < bitmap.Height; y++)
{
byte bColorIndex = *(bitmapData.Scan0 + y * bitmapData.Stride + x);
Color currentColor = bitmap.Palette.Entries[bColorIndex];
}
}
bitmap.UnlockBits(bitmapData);
------解决方案--------------------
byte* p = bitmapData.Scan0;
马虎大意了,这一句要改成
byte* p = (byte*)bitmapData.Scan0;