diff --git a/bitmap/goBitmap.h b/bitmap/goBitmap.h index 35dcd49..3fa3264 100644 --- a/bitmap/goBitmap.h +++ b/bitmap/goBitmap.h @@ -158,3 +158,14 @@ MMRGBHex bitmap_get_color(MMBitmapRef bitmap, size_t x, size_t y){ return MMRGBHexAtPoint(bitmap, point.x, point.y); } + +MMPoint bitmap_find_color(MMBitmapRef bitmap, MMRGBHex color, float tolerance){ + MMRect rect = MMBitmapGetBounds(bitmap); + MMPoint point = {-1, -1}; + + if (findColorInRect(bitmap, color, &point, rect, tolerance) == 0) { + return point; + } + + return point; +} diff --git a/robotgo.go b/robotgo.go index b7ded7e..76e87d3 100644 --- a/robotgo.go +++ b/robotgo.go @@ -55,7 +55,7 @@ import ( ) const ( - version string = "v0.46.0.382, Pyrenees Mountains!" + version string = "v0.46.0.385, Pyrenees Mountains!" ) // GetVersion get version @@ -736,6 +736,23 @@ func GetColor(bitmap C.MMBitmapRef, x, y int) C.MMRGBHex { return color } +// FindColor find bitmap color +func FindColor(bitmap C.MMBitmapRef, color C.MMRGBHex, args ...float32) (int, int) { + var tolerance C.float + + if len(args) > 2 { + tolerance = C.float(args[2]) + } else { + tolerance = 0.5 + } + + pos := C.bitmap_find_color(bitmap, color, tolerance) + x := int(pos.x) + y := int(pos.y) + + return x, y +} + /* ___________ ____ _______ .__ __. .___________. | ____\ \ / / | ____|| \ | | | |