Skip to content

Commit

Permalink
added tolerance for pixel color for better windows 7 compatibility
Browse files Browse the repository at this point in the history
tiemonl committed Aug 26, 2018

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
1 parent 7f18d67 commit e2e5514
Showing 2 changed files with 9 additions and 1 deletion.
4 changes: 3 additions & 1 deletion fisher/Form1.cs
Original file line number Diff line number Diff line change
@@ -197,8 +197,10 @@ private void backgroundThread_DoWork(object sender, DoWorkEventArgs e) {
printMessage(baitUsed, baitToUse, " bait used.\nWaiting for cast result.");
Invoke(new Action(() => Refresh()));
//performs cast
Invoke(new Action(() => Cursor.Position = locationTimerCaughtFish));
Color color = helper.GetPixelColor(locationTimerCaughtFish);
if (color == colorTimerCaughtFishKong || color == colorTimerCaughtFishSteam) {
//if (color == colorTimerCaughtFishKong || color == colorTimerCaughtFishSteam) {
if (helper.AreColorsSimilar(color, colorTimerCaughtFishKong, 20)) {
printMessage(baitUsed, baitToUse, " bait used.\nPerforming catch.");
Invoke(new Action(() => Refresh()));
Invoke(new Action(() => helper.catchFish(location100Position, oneHundredCatchColor)));
6 changes: 6 additions & 0 deletions fisher/MethodHelper.cs
Original file line number Diff line number Diff line change
@@ -89,6 +89,12 @@ public Color GetPixelColor(Point location) {
return color;
}

public bool AreColorsSimilar(Color c1, Color c2, int tolerance) {
return Math.Abs(c1.R - c2.R) < tolerance &&
Math.Abs(c1.G - c2.G) < tolerance &&
Math.Abs(c1.B - c2.B) < tolerance;
}

public Dictionary<int, Bitmap> GetScreenShot(bool saveScreenshot) {
//Using `SystemInformation.VirtualScreen` rather than `Screen.PrimaryScreen`
//ensures that the program can look at all screens for the start button.

0 comments on commit e2e5514

Please sign in to comment.