just free internal bitmap and add bitmapStr example

This commit is contained in:
vcaesar 2018-07-28 23:07:40 +08:00
parent 5ab8d85856
commit 111d1badb1
4 changed files with 17 additions and 7 deletions

1
.gitignore vendored
View File

@ -67,3 +67,4 @@ _testmain.go
# Project-local glide cache, RE: https://github.com/Masterminds/glide/issues/736
.glide/
examples/bitmap/teststr.png

View File

@ -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;
}

View File

@ -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")

View File

@ -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)