From 0d7798c6c373ce405b53e257e560448da6f431b9 Mon Sep 17 00:00:00 2001 From: vcaesar Date: Fri, 28 May 2021 14:31:05 -0400 Subject: [PATCH 1/2] add byte to image function --- robotgo.go | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/robotgo.go b/robotgo.go index 1648574..661c4a4 100644 --- a/robotgo.go +++ b/robotgo.go @@ -49,6 +49,7 @@ package robotgo import "C" import ( + "bytes" "fmt" "image" @@ -1126,6 +1127,12 @@ func DecodeImg(path string) (image.Image, string, error) { return imgo.DecodeFile(path) } +// ByteToImg convert []byte to image.Image +func ByteToImg(b []byte) (image.Image, error) { + img, _, err := image.Decode(bytes.NewReader(b)) + return img, err +} + // ToImage convert C.MMBitmapRef to standard image.Image func ToImage(bit C.MMBitmapRef) image.Image { bmp1 := ToBitmap(bit) From cad782738cf14ec7ba125ce0aa6313f9d5fcc21c Mon Sep 17 00:00:00 2001 From: vcaesar Date: Sat, 29 May 2021 09:58:26 -0400 Subject: [PATCH 2/2] update free bitmap fixed #333 --- robotgo.go | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/robotgo.go b/robotgo.go index 661c4a4..e0e2f40 100644 --- a/robotgo.go +++ b/robotgo.go @@ -978,7 +978,7 @@ func FindBitmap(bit C.MMBitmapRef, args ...interface{}) (int, int) { fx, fy := internalFindBitmap(bit, sbit, tolerance) // FreeBitmap(bit) - if len(args) <= 0 { + if len(args) <= 0 || (len(args) > 0 && args[0] == nil) { FreeBitmap(sbit) } @@ -1011,7 +1011,7 @@ func FindPic(path string, args ...interface{}) (int, int) { fx, fy := internalFindBitmap(openbit, sbit, tolerance) FreeBitmap(openbit) - if len(args) <= 0 { + if len(args) <= 0 || (len(args) > 0 && args[0] == nil) { FreeBitmap(sbit) } @@ -1056,7 +1056,7 @@ func FindEveryBitmap(bit C.MMBitmapRef, args ...interface{}) (posArr []MPoint) { pos := C.find_every_bitmap(bit, sbit, tolerance, &lpos) // FreeBitmap(bit) - if len(args) <= 0 { + if len(args) <= 0 || (len(args) > 0 && args[0] == nil) { FreeBitmap(sbit) } if pos == nil { @@ -1299,7 +1299,7 @@ func FindColor(color CHex, args ...interface{}) (int, int) { } pos := C.bitmap_find_color(bitmap, C.MMRGBHex(color), tolerance) - if len(args) <= 0 { + if len(args) <= 0 || (len(args) > 0 && args[0] == nil) { FreeBitmap(bitmap) } @@ -1356,7 +1356,7 @@ func FindEveryColor(color CHex, args ...interface{}) (posArr []MPoint) { } pos := C.bitmap_find_every_color(bitmap, C.MMRGBHex(color), tolerance, &lpos) - if len(args) <= 0 { + if len(args) <= 0 || (len(args) > 0 && args[0] == nil) { FreeBitmap(bitmap) } @@ -1396,7 +1396,7 @@ func CountColor(color CHex, args ...interface{}) int { } count := C.bitmap_count_of_color(bitmap, C.MMRGBHex(color), tolerance) - if len(args) <= 0 { + if len(args) <= 0 || (len(args) > 0 && args[0] == nil) { FreeBitmap(bitmap) }