From 111d1badb1a2da3907fb004bc830e6f56181d9d4 Mon Sep 17 00:00:00 2001 From: vcaesar Date: Sat, 28 Jul 2018 23:07:40 +0800 Subject: [PATCH] just free internal bitmap and add bitmapStr example --- .gitignore | 1 + bitmap/goBitmap.h | 4 ++-- examples/bitmap/main.go | 3 +++ robotgo.go | 16 +++++++++++----- 4 files changed, 17 insertions(+), 7 deletions(-) diff --git a/.gitignore b/.gitignore index d776a0f..f0bc8f6 100644 --- a/.gitignore +++ b/.gitignore @@ -67,3 +67,4 @@ _testmain.go # Project-local glide cache, RE: https://github.com/Masterminds/glide/issues/736 .glide/ +examples/bitmap/teststr.png diff --git a/bitmap/goBitmap.h b/bitmap/goBitmap.h index f9e2956..7b1f81a 100644 --- a/bitmap/goBitmap.h +++ b/bitmap/goBitmap.h @@ -157,8 +157,8 @@ MMBitmapRef bitmap_from_string(const char *str){ MMBMPStringError err; if ((bitmap = createMMBitmapFromString( - (unsigned char*)str, len, &err)) - == NULL) { + (unsigned char*)str, len, &err ) + ) == NULL) { return NULL; } diff --git a/examples/bitmap/main.go b/examples/bitmap/main.go index df48b3d..22b2a5c 100644 --- a/examples/bitmap/main.go +++ b/examples/bitmap/main.go @@ -83,6 +83,9 @@ func bitmap() { // sbitmap := robotgo.BitmapFromstring(bitstr, 2) // fmt.Println("...", sbitmap) + sbitmap := robotgo.BitmapStr(bitstr) + fmt.Println("bitmap str...", sbitmap) + robotgo.SaveBitmap(sbitmap, "teststr.png") // saves image to absolute filepath in the given format robotgo.SaveBitmap(bitmap, "test.png") diff --git a/robotgo.go b/robotgo.go index 897e6de..df3a688 100644 --- a/robotgo.go +++ b/robotgo.go @@ -819,8 +819,10 @@ func FindBitmap(bit C.MMBitmapRef, args ...interface{}) (int, int) { } fx, fy := internalFindBitmap(bit, sbit, tolerance) - FreeBitmap(bit) - FreeBitmap(sbit) + // FreeBitmap(bit) + if len(args) <= 0 { + FreeBitmap(sbit) + } return fx, fy } @@ -851,7 +853,9 @@ func FindPic(path string, args ...interface{}) (int, int) { fx, fy := internalFindBitmap(openbit, sbit, tolerance) FreeBitmap(openbit) - FreeBitmap(sbit) + if len(args) <= 0 { + FreeBitmap(sbit) + } return fx, fy } @@ -890,8 +894,10 @@ func FindEveryBitmap(bit C.MMBitmapRef, args ...interface{}) (int, int) { } pos := C.find_every_bitmap(bit, sbit, tolerance, &lpos) - FreeBitmap(bit) - FreeBitmap(sbit) + // FreeBitmap(bit) + if len(args) <= 0 { + FreeBitmap(sbit) + } // fmt.Println("pos----", pos) return int(pos.x), int(pos.y)