From b55f438c1b084d51a08b58efac3ce7bbde7f3591 Mon Sep 17 00:00:00 2001 From: vcaesar Date: Sat, 23 Dec 2017 23:38:35 +0800 Subject: [PATCH] add get pixel color return hex --- robotgo.go | 14 ++++++++++++-- screen/goScreen.h | 15 +++++++++++++++ 2 files changed, 27 insertions(+), 2 deletions(-) diff --git a/robotgo.go b/robotgo.go index f2c56ff..dcefaba 100644 --- a/robotgo.go +++ b/robotgo.go @@ -62,7 +62,7 @@ import ( ) const ( - version string = "v0.47.0.445, Mount Cook!" + version string = "v0.47.0.447, Mount Cook!" ) type ( @@ -112,10 +112,20 @@ func Try(fun func(), handler func(interface{})) { |_______/ \______|| _| `._____||_______||_______||__| \__| */ -// GetPixelColor get pixel color +// GetPxColor get pixel color return C.MMRGBHex +func GetPxColor(x, y int) C.MMRGBHex { + cx := C.size_t(x) + cy := C.size_t(y) + + color := C.get_Pixel_Color(cx, cy) + return color +} + +// GetPixelColor get pixel color return string func GetPixelColor(x, y int) string { cx := C.size_t(x) cy := C.size_t(y) + color := C.aGetPixelColor(cx, cy) // color := C.aGetPixelColor(x, y) gcolor := C.GoString(color) diff --git a/screen/goScreen.h b/screen/goScreen.h index f0ae81e..98a4f03 100644 --- a/screen/goScreen.h +++ b/screen/goScreen.h @@ -19,6 +19,21 @@ void padHex(MMRGBHex color, char* hex){ snprintf(hex, 7, "%06x", color); } +MMRGBHex get_Pixel_Color(size_t x, size_t y){ + MMBitmapRef bitmap; + MMRGBHex color; + + if (!pointVisibleOnMainDisplay(MMPointMake(x, y))){ + return color; + } + + bitmap = copyMMBitmapFromDisplayInRect(MMRectMake(x, y, 1, 1)); + // bitmap = MMRectMake(x, y, 1, 1); + + color = MMRGBHexAtPoint(bitmap, 0, 0); + + return color; +} char* aGetPixelColor(size_t x, size_t y){ MMBitmapRef bitmap;