mirror of
https://github.com/go-vgo/robotgo.git
synced 2025-05-31 06:13:55 +00:00
Add find some color
This commit is contained in:
parent
6d2317ee69
commit
ea0b910646
@ -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;
|
||||
}
|
||||
|
19
robotgo.go
19
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
|
||||
}
|
||||
|
||||
/*
|
||||
___________ ____ _______ .__ __. .___________.
|
||||
| ____\ \ / / | ____|| \ | | | |
|
||||
|
Loading…
Reference in New Issue
Block a user