diff --git a/bitmap/goBitmap.h b/bitmap/goBitmap.h index dfba1de..35dcd49 100644 --- a/bitmap/goBitmap.h +++ b/bitmap/goBitmap.h @@ -145,3 +145,16 @@ MMBitmapRef get_Portion(MMBitmapRef bit_map, MMRect rect){ portion = copyMMBitmapFromPortion(bit_map, rect); return portion; } + +MMRGBHex bitmap_get_color(MMBitmapRef bitmap, size_t x, size_t y){ + if (!bitmap_ready(bitmap)) return 0; + + MMPoint point; + point = MMPointMake(x, y); + + if (!MMBitmapPointInBounds(bitmap, point)) { + return 0; + } + + return MMRGBHexAtPoint(bitmap, point.x, point.y); +} diff --git a/examples/bitmap/main.go b/examples/bitmap/main.go index 9193ead..9bf7106 100644 --- a/examples/bitmap/main.go +++ b/examples/bitmap/main.go @@ -30,6 +30,9 @@ func main() { bitmap := robotgo.CaptureScreen(100, 200, 30, 40) fmt.Println("CaptureScreen...", bitmap) + color := robotgo.GetColor(bitmap, 1, 2) + fmt.Println("color...", color) + // searches for needle in bitmap fx, fy := robotgo.FindBit(bitmap) fmt.Println("FindBitmap------", fx, fy) diff --git a/examples/main.go b/examples/main.go index 5daf5aa..bf48cf7 100644 --- a/examples/main.go +++ b/examples/main.go @@ -140,6 +140,9 @@ func bitmap() { bitmap := robotgo.CaptureScreen(100, 200, 30, 40) fmt.Println("CaptureScreen...", bitmap) + color := robotgo.GetColor(bitmap, 1, 2) + fmt.Println("color...", color) + // searches for needle in bitmap fx, fy := robotgo.FindBit(bitmap) fmt.Println("FindBitmap------", fx, fy) diff --git a/robotgo.go b/robotgo.go index 4bf0cde..b7ded7e 100644 --- a/robotgo.go +++ b/robotgo.go @@ -729,6 +729,13 @@ func DeepCopyBit(bitmap C.MMBitmapRef) C.MMBitmapRef { return bit } +// GetColor get bitmap color +func GetColor(bitmap C.MMBitmapRef, x, y int) C.MMRGBHex { + color := C.bitmap_get_color(bitmap, C.size_t(x), C.size_t(y)) + + return color +} + /* ___________ ____ _______ .__ __. .___________. | ____\ \ / / | ____|| \ | | | |