Getting (Bitmap region is already locked) error when locking two bitmaps to compare pixels.
Bitmap b = (Bitmap)pictureBox1.Image;
Bitmap b2 = (Bitmap)pictureBox1.Image;
BitmapData bmData = b.LockBits(new Rectangle(0, 0, b.Width, b.Height), ImageLockMode.ReadWrite, PixelFormat.Format24bppRgb);
BitmapData bmData2 = b2.LockBits(new Rectangle(b.Width, b.Height, b2.Width, b2.Height), ImageLockMode.ReadWrite, PixelFormat.Format24bppRgb);
int stride = bmData.Stride;
int stride2 = bmData2.Stride;
unsafe
{
byte* p = (byte*)bmData.Scan0;
byte* p2 = (byte*)bmData2.Scan0;
int nOffset,nOffSet2;
int nWidth,nWidth2;
NOffSet(b, stride, out nOffset, out nWidth);
NOffSet(b2, stride2, out nOffSet2, out nWidth2);
for(int y=0;y<b.Height;++y)
{
for (int x = 0; x < nWidth; ++x)
{
if (p[0].Equals(p2[0]))
listBox1.Items.Add(string.Format("({0},{1}) :{2}", x, y, p2[0]));
++p; ++p2;
}
p += nOffset;
}
}
b.UnlockBits(bmData);