我需要快速读取 bmp 的 getpixel,但我使用的 LockBits 非常低
private void LockUnlockBitsExample(Bitmap bmp)
{
Rectangle rect = new Rectangle(0, 0, bmp.Width, bmp.Height);
System.Drawing.Imaging.BitmapData bmpData =
bmp.LockBits(rect, System.Drawing.Imaging.ImageLockMode.ReadWrite,
bmp.PixelFormat);
IntPtr ptr = bmpData.Scan0;
int bytes = Math.Abs(bmpData.Stride) * bmp.Height;
rgbValues = new byte[bytes];
System.Runtime.InteropServices.Marshal.Copy(ptr, rgbValues, 0, bytes);
bmp.UnlockBits(bmpData);
}
和这个功能
private Color GetMyPixel(byte[] rgbValues,Bitmap bmp, int x,int y )
{
int index= (bmp.Width*y+x)*3;
Color MyColor = Color.FromArgb(rgbValues[index], rgbValues[index + 1], rgbValues[index + 2]);
return MyColor;
}
但我的函数的输出与原始 getpixel 不同