mirror of
https://github.com/go-vgo/robotgo.git
synced 2025-06-01 06:33:56 +00:00
add count bitmap color func
This commit is contained in:
parent
6434928f2d
commit
97f54f7f3d
@ -215,3 +215,10 @@ MMPoint bitmap_find_color(MMBitmapRef bitmap, MMRGBHex color, float tolerance){
|
||||
|
||||
return point;
|
||||
}
|
||||
|
||||
int bitmap_count_of_color(MMBitmapRef bitmap, MMRGBHex color, float tolerance){
|
||||
if (!bitmap_ready(bitmap)) return 0;
|
||||
MMRect rect = MMBitmapGetBounds(bitmap);
|
||||
|
||||
return countOfColorsInRect(bitmap, color, rect, tolerance);
|
||||
}
|
||||
|
33
robotgo.go
33
robotgo.go
@ -62,7 +62,7 @@ import (
|
||||
)
|
||||
|
||||
const (
|
||||
version string = "v0.47.0.471, Mount Cook!"
|
||||
version string = "v0.47.0.472, Mount Cook!"
|
||||
)
|
||||
|
||||
type (
|
||||
@ -997,6 +997,37 @@ func FindColorCS(x, y, w, h int, color CHex, args ...float32) (int, int) {
|
||||
return rx, ry
|
||||
}
|
||||
|
||||
// CountColor count bitmap color
|
||||
func CountColor(bitmap C.MMBitmapRef, color CHex, args ...float32) int {
|
||||
var tolerance C.float
|
||||
|
||||
if len(args) > 0 {
|
||||
tolerance = C.float(args[0])
|
||||
} else {
|
||||
tolerance = 0.5
|
||||
}
|
||||
|
||||
count := C.bitmap_count_of_color(bitmap, C.MMRGBHex(color), tolerance)
|
||||
|
||||
return int(count)
|
||||
}
|
||||
|
||||
// CountColorCS count bitmap color by CaptureScreen
|
||||
func CountColorCS(x, y, w, h int, color CHex, args ...float32) int {
|
||||
var tolerance float32
|
||||
|
||||
if len(args) > 0 {
|
||||
tolerance = args[0]
|
||||
} else {
|
||||
tolerance = 0.5
|
||||
}
|
||||
|
||||
bitmap := CaptureScreen(x, y, w, h)
|
||||
rx := CountColor(bitmap, color, tolerance)
|
||||
|
||||
return rx
|
||||
}
|
||||
|
||||
/*
|
||||
___________ ____ _______ .__ __. .___________.
|
||||
| ____\ \ / / | ____|| \ | | | |
|
||||
|
Loading…
Reference in New Issue
Block a user