0
특정 색상을 가진 첫 번째 픽셀을 클릭하는 프로그램을 작성하려고합니다. 불행히도, 때로는 내 프로그램이 화면에 실제로 색상이 있음을 감지 할 수없는 것으로 보입니다. 화면의 스크린 샷을 찍은 다음 GetPixel() 메서드를 사용하여 모든 픽셀의 색상을 찾습니다. 여기 Color Clicker 정확하지 않음
내 방법은 제가 사용 :private static Point FindFirstColor(Color color)
{
int searchValue = color.ToArgb();
Point location = Point.Empty;
using (Bitmap bmp = GetScreenShot())
{
for (int x = 0; x < bmp.Width; x++)
{
for (int y = 0; y < bmp.Height; y++)
{
if (searchValue.Equals(bmp.GetPixel(x, y).ToArgb()))
{
location = new Point(x, y);
}
}
}
}
return location;
}
내 화면의 스크린 샷을하기 위해, 내가 사용
private static Bitmap GetScreenShot()
{
Bitmap result = new Bitmap(Screen.PrimaryScreen.Bounds.Width, Screen.PrimaryScreen.Bounds.Height, PixelFormat.Format32bppArgb);
{
using (Graphics gfx = Graphics.FromImage(result))
{
gfx.CopyFromScreen(Screen.PrimaryScreen.Bounds.X, Screen.PrimaryScreen.Bounds.Y, 0, 0, Screen.PrimaryScreen.Bounds.Size, CopyPixelOperation.SourceCopy);
}
}
return result;
}
을 나는이에 알고있는 색상을 사용하는 경우에도 화면, 여전히 Point.Empty를 반환합니다. 이것에 대한 이유는 무엇입니까?
당신이'GetScreenShot()'않습니다 정확하게 제공하시기 바랍니다 수 있습니까? :) –
첫 번째 일치하는 픽셀이 필요한 경우 첫 번째 일치를 얻은 후 루프를 벗어나는 이유는 무엇입니까? – Anujith
나는 여전히 부정확성에 문제가있다. 한 번 실행하면 색상을 감지합니다. 다른 시간에, 그것은하지 않습니다 ... 나는 이러한 실행 사이에 어떤 코드를 변경하지 않습니다. 무엇이 문제 일 수 있습니까? – user1594328