주 화면을 캡쳐하고 비트 맵으로 변환 한 다음 비트 맵 "키"로 스크린 샷 비트 맵을 검색하는 프로그램을 작성 중입니다. 비트 맵 "키"를 전체 그림과 비교하여 일치하는 위치를 찾은 다음 커서를 위치로 이동 한 다음 마우스를 클릭합니다. bmpLogin
이 (가) null 인 문제가 있습니다. Mopar/Mopar/Resources/bmpLogin.bmp
에 비트 맵 키가 있습니다. 비교를 위해이 이미지를 찾을 수없는 것 같습니다. 다음은 관련 코드입니다.다른 비트 맵 내의 비트 맵 위치 찾기
시작 버튼 :
private void startBotButton(object sender, EventArgs e)
{
//Screenshot
//This is where we will be writing the loop for the bot
Bitmap bmpScreenshot = Screenshot();
//Set the background of the form the screenshot that was taken
this.BackgroundImage = bmpScreenshot;
//Find the node and check if it exists within the screenshot
Point location;
bool success = FindBitmap(Properties.Resources.bmpLogin, bmpScreenshot, out location);
//Check if it found the node in the bitmap
if (success == false)
{
MessageBox.Show("Couldn't find the node");
return;
}
//Move the mouse to the node
Cursor.Position = location;
//click
MouseClick();
}
스크린 샷 : 비트 맵을 검색
//Screenshot the screen
private Bitmap Screenshot()
{
//This is where we will store the screenshot
Bitmap bmpScreenshot = new Bitmap(Screen.PrimaryScreen.Bounds.Width, Screen.PrimaryScreen.Bounds.Height);
//Create a graphics object so we can draw the screen in the bitmap
Graphics g = Graphics.FromImage(bmpScreenshot);
//Copy from screen to bitmap
g.CopyFromScreen(0, 0, 0, 0, Screen.PrimaryScreen.Bounds.Size);
//Return the screenshot
return bmpScreenshot;
}
:
/// <summary>
/// Find the location of a bitmap within another bitmap and return if it was successfully found
/// </summary>
/// <param name="bmpNeedle">The image we want to find</param>
/// <param name="bmpHaystack">Where we want to search for the image</param>
/// <param name="location">Where we found the image</param>
/// <returns>If the bmpNeedle was found successfully</returns>
private bool FindBitmap(Bitmap bmpNeedle, Bitmap bmpHaystack, out Point location)
{
if (bmpNeedle == null || bmpHaystack == null)
{
location = new Point();
return false;
}
for (int outerX = 0; outerX < bmpHaystack.Width - bmpNeedle.Width; outerX++)
{
for (int outerY = 0; outerY < bmpHaystack.Height - bmpNeedle.Height; outerY++)
{
for (int innerX = 0; innerX < bmpNeedle.Width; innerX++)
{
for (int innerY = 0; innerY < bmpNeedle.Height; innerY++)
{
Color cNeedle = bmpNeedle.GetPixel(innerX, innerY);
Color cHaystack = bmpHaystack.GetPixel(innerX + outerX, innerY + outerY);
if (cNeedle.R != cHaystack.R || cNeedle.G != cHaystack.G || cNeedle.B != cHaystack.B)
{
goto notFound;
}
}
}
location = new Point(outerX, outerY);
return true;
notFound:
continue;
}
}
location = Point.Empty;
return false;
}
첫 번째 * GetPixel *은 너무 느립니다. * 잠금 - 비트 맵을 잠금 해제하십시오. 둘째로 @DevNull이 말하는 것. –