mirror of
https://github.com/go-vgo/robotgo.git
synced 2025-06-02 23:23:55 +00:00
fix float args and update examples [add freeBitmap and update findColor]
This commit is contained in:
parent
c6d60bd3f2
commit
814c5e6980
@ -30,34 +30,40 @@ func bitmap() {
|
|||||||
|
|
||||||
// gets part of the screen
|
// gets part of the screen
|
||||||
bitmap := robotgo.CaptureScreen(100, 200, 30, 40)
|
bitmap := robotgo.CaptureScreen(100, 200, 30, 40)
|
||||||
|
defer robotgo.FreeBitmap(bitmap)
|
||||||
fmt.Println("CaptureScreen...", bitmap)
|
fmt.Println("CaptureScreen...", bitmap)
|
||||||
|
|
||||||
gbit := robotgo.ToBitmap(bitmap)
|
gbit := robotgo.ToBitmap(bitmap)
|
||||||
fmt.Println("go bitmap", gbit, gbit.Width)
|
fmt.Println("go bitmap", gbit, gbit.Width)
|
||||||
|
|
||||||
cbit := robotgo.ToCBitmap(gbit)
|
cbit := robotgo.ToCBitmap(gbit)
|
||||||
|
// defer robotgo.FreeBitmap(cbit)
|
||||||
log.Println("cbit == bitmap: ", cbit == bitmap)
|
log.Println("cbit == bitmap: ", cbit == bitmap)
|
||||||
robotgo.SaveBitmap(cbit, "tocbitmap.png")
|
robotgo.SaveBitmap(cbit, "tocbitmap.png")
|
||||||
|
|
||||||
// find the color in bitmap
|
// find the color in bitmap
|
||||||
color := robotgo.GetColor(bitmap, 1, 2)
|
color := robotgo.GetColor(bitmap, 1, 2)
|
||||||
fmt.Println("color...", color)
|
fmt.Println("color...", color)
|
||||||
cx, cy := robotgo.FindColor(bitmap, robotgo.CHex(color), 1.0)
|
cx, cy := robotgo.FindColor(robotgo.CHex(color), bitmap, 1.0)
|
||||||
fmt.Println("pos...", cx, cy)
|
fmt.Println("pos...", cx, cy)
|
||||||
cx, cy = robotgo.FindColor(bitmap, 0xAADCDC)
|
cx, cy = robotgo.FindColor(robotgo.CHex(color))
|
||||||
fmt.Println("pos...", cx, cy)
|
|
||||||
cx, cy = robotgo.FindColorCS(388, 179, 300, 300, 0xAADCDC)
|
|
||||||
fmt.Println("pos...", cx, cy)
|
fmt.Println("pos...", cx, cy)
|
||||||
|
|
||||||
cnt := robotgo.CountColor(bitmap, 0xAADCDC)
|
cx, cy = robotgo.FindColor(0xAADCDC, bitmap)
|
||||||
|
fmt.Println("pos...", cx, cy)
|
||||||
|
cx, cy = robotgo.FindColorCS(0xAADCDC, 388, 179, 300, 300)
|
||||||
|
fmt.Println("pos...", cx, cy)
|
||||||
|
|
||||||
|
cnt := robotgo.CountColor(0xAADCDC, bitmap)
|
||||||
fmt.Println("count...", cnt)
|
fmt.Println("count...", cnt)
|
||||||
cnt1 := robotgo.CountColorCS(10, 20, 30, 40, 0xAADCDC)
|
cnt1 := robotgo.CountColorCS(0xAADCDC, 10, 20, 30, 40)
|
||||||
fmt.Println("count...", cnt1)
|
fmt.Println("count...", cnt1)
|
||||||
|
|
||||||
count := robotgo.CountBitmap(abitMap, bitmap)
|
count := robotgo.CountBitmap(abitMap, bitmap)
|
||||||
fmt.Println("count...", count)
|
fmt.Println("count...", count)
|
||||||
|
|
||||||
bit := robotgo.CaptureScreen(1, 2, 40, 40)
|
bit := robotgo.CaptureScreen(1, 2, 40, 40)
|
||||||
|
defer robotgo.FreeBitmap(bit)
|
||||||
fmt.Println("CaptureScreen...", bit)
|
fmt.Println("CaptureScreen...", bit)
|
||||||
|
|
||||||
// searches for needle in bitmap
|
// searches for needle in bitmap
|
||||||
@ -120,6 +126,7 @@ func bitmap() {
|
|||||||
|
|
||||||
// free the bitmap
|
// free the bitmap
|
||||||
robotgo.FreeBitmap(abitMap)
|
robotgo.FreeBitmap(abitMap)
|
||||||
|
// robotgo.FreeBitmap(bitmap)
|
||||||
}
|
}
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
|
12
robotgo.go
12
robotgo.go
@ -1075,7 +1075,7 @@ func FindColor(color CHex, args ...interface{}) (int, int) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if len(args) > 1 {
|
if len(args) > 1 {
|
||||||
tolerance = C.float(args[1].(float32))
|
tolerance = C.float(args[1].(float64))
|
||||||
}
|
}
|
||||||
|
|
||||||
pos := C.bitmap_find_color(bitmap, C.MMRGBHex(color), tolerance)
|
pos := C.bitmap_find_color(bitmap, C.MMRGBHex(color), tolerance)
|
||||||
@ -1090,8 +1090,8 @@ func FindColor(color CHex, args ...interface{}) (int, int) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// FindColorCS findcolor by CaptureScreen
|
// FindColorCS findcolor by CaptureScreen
|
||||||
func FindColorCS(color CHex, x, y, w, h int, args ...float32) (int, int) {
|
func FindColorCS(color CHex, x, y, w, h int, args ...float64) (int, int) {
|
||||||
var tolerance float32 = 0.01
|
var tolerance = 0.01
|
||||||
|
|
||||||
if len(args) > 0 {
|
if len(args) > 0 {
|
||||||
tolerance = args[0]
|
tolerance = args[0]
|
||||||
@ -1118,7 +1118,7 @@ func CountColor(color CHex, args ...interface{}) int {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if len(args) > 1 {
|
if len(args) > 1 {
|
||||||
tolerance = C.float(args[1].(float32))
|
tolerance = C.float(args[1].(float64))
|
||||||
}
|
}
|
||||||
|
|
||||||
count := C.bitmap_count_of_color(bitmap, C.MMRGBHex(color), tolerance)
|
count := C.bitmap_count_of_color(bitmap, C.MMRGBHex(color), tolerance)
|
||||||
@ -1130,8 +1130,8 @@ func CountColor(color CHex, args ...interface{}) int {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// CountColorCS count bitmap color by CaptureScreen
|
// CountColorCS count bitmap color by CaptureScreen
|
||||||
func CountColorCS(color CHex, x, y, w, h int, args ...float32) int {
|
func CountColorCS(color CHex, x, y, w, h int, args ...float64) int {
|
||||||
var tolerance float32 = 0.01
|
var tolerance = 0.01
|
||||||
|
|
||||||
if len(args) > 0 {
|
if len(args) > 0 {
|
||||||
tolerance = args[0]
|
tolerance = args[0]
|
||||||
|
Loading…
Reference in New Issue
Block a user