0
이미지의 모든 픽셀을 스캔하고 색상이 분홍색 인 픽셀을 찾을 때마다 프로그램을 만듭니다. 픽셀을 검정색으로 만듭니다. 그러나 이미지 위에 두 개가있는 경우 분홍색 픽셀을 찾지 않는 것 같습니다. 내가 LockBits를 올바르게 사용하고 있는지 모르겠다. 아마도 그것을 잘못 사용하고있을 것이다. 누군가 제가이 문제를 해결할 수 있도록 도와 주시겠습니까? 당신은 배열로 픽셀 데이터를 복사 할 필요가 없습니다비트를 잠그면 픽셀을 찾지 못합니다.
Bitmap bitmap = pictureBox1.Image as Bitmap;
System.Drawing.Imaging.BitmapData d = bitmap.LockBits(new Rectangle(0, 0, bitmap.Width, bitmap.Height), System.Drawing.Imaging.ImageLockMode.ReadWrite, bitmap.PixelFormat);
IntPtr ptr = d.Scan0;
byte[] rgbs = new byte[Math.Abs(d.Stride) * bitmap.Height];
Marshal.Copy(ptr, rgbs, 0, rgbs.Length);
Graphics g = pictureBox1.CreateGraphics();
for (int index = 2; index < rgbs.Length; index += 3)
{
if (rgbs[index] == 255 && rgbs[index - 1] == 0 && rgbs[index - 2] == 255) // If color = RGB(255, 0, 255) Then ...
{
// This never gets executed!
rgbs[index] = 0;
rgbs[index - 1] = 0;
rgbs[index - 2] = 0;
}
}
Marshal.Copy(rgbs, 0, ptr, rgbs.Length); // Copy rgb values back to the memory location of the bitmap.
pictureBox1.Image = bitmap;
bitmap.UnlockBits(d);