diff --git a/examples/bitmap/main.go b/examples/bitmap/main.go index 22b2a5c..a9f8452 100644 --- a/examples/bitmap/main.go +++ b/examples/bitmap/main.go @@ -30,34 +30,40 @@ func bitmap() { // gets part of the screen bitmap := robotgo.CaptureScreen(100, 200, 30, 40) + defer robotgo.FreeBitmap(bitmap) fmt.Println("CaptureScreen...", bitmap) gbit := robotgo.ToBitmap(bitmap) fmt.Println("go bitmap", gbit, gbit.Width) cbit := robotgo.ToCBitmap(gbit) + // defer robotgo.FreeBitmap(cbit) log.Println("cbit == bitmap: ", cbit == bitmap) robotgo.SaveBitmap(cbit, "tocbitmap.png") // find the color in bitmap color := robotgo.GetColor(bitmap, 1, 2) 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) - cx, cy = robotgo.FindColor(bitmap, 0xAADCDC) - fmt.Println("pos...", cx, cy) - cx, cy = robotgo.FindColorCS(388, 179, 300, 300, 0xAADCDC) + cx, cy = robotgo.FindColor(robotgo.CHex(color)) 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) - cnt1 := robotgo.CountColorCS(10, 20, 30, 40, 0xAADCDC) + cnt1 := robotgo.CountColorCS(0xAADCDC, 10, 20, 30, 40) fmt.Println("count...", cnt1) count := robotgo.CountBitmap(abitMap, bitmap) fmt.Println("count...", count) bit := robotgo.CaptureScreen(1, 2, 40, 40) + defer robotgo.FreeBitmap(bit) fmt.Println("CaptureScreen...", bit) // searches for needle in bitmap @@ -120,6 +126,7 @@ func bitmap() { // free the bitmap robotgo.FreeBitmap(abitMap) + // robotgo.FreeBitmap(bitmap) } func main() { diff --git a/robotgo.go b/robotgo.go index f16a9bb..f4d4921 100644 --- a/robotgo.go +++ b/robotgo.go @@ -1075,7 +1075,7 @@ func FindColor(color CHex, args ...interface{}) (int, int) { } 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) @@ -1090,8 +1090,8 @@ func FindColor(color CHex, args ...interface{}) (int, int) { } // FindColorCS findcolor by CaptureScreen -func FindColorCS(color CHex, x, y, w, h int, args ...float32) (int, int) { - var tolerance float32 = 0.01 +func FindColorCS(color CHex, x, y, w, h int, args ...float64) (int, int) { + var tolerance = 0.01 if len(args) > 0 { tolerance = args[0] @@ -1118,7 +1118,7 @@ func CountColor(color CHex, args ...interface{}) int { } 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) @@ -1130,8 +1130,8 @@ func CountColor(color CHex, args ...interface{}) int { } // CountColorCS count bitmap color by CaptureScreen -func CountColorCS(color CHex, x, y, w, h int, args ...float32) int { - var tolerance float32 = 0.01 +func CountColorCS(color CHex, x, y, w, h int, args ...float64) int { + var tolerance = 0.01 if len(args) > 0 { tolerance = args[0]