add free bitmap array support and Update README.md

This commit is contained in:
vcaesar 2021-10-12 12:03:50 -04:00
parent 1498a7d32e
commit 336b7cea9f
3 changed files with 42 additions and 1 deletions

View File

@ -186,6 +186,7 @@ import (
"fmt"
"github.com/go-vgo/robotgo"
"github.com/vcaesar/imgo"
)
func main() {
@ -197,6 +198,13 @@ func main() {
sx, sy := robotgo.GetScreenSize()
fmt.Println("get screen size: ", sx, sy)
bit := robotgo.CaptureScreen(10, 10, 30, 30)
defer robotgo.FreeBitmap(bit)
robotgo.SaveBimap(bit, "test_1.png")
img := robotgo.ToImage(bit)
imgo.Save("test.png", img)
}
```
@ -248,6 +256,15 @@ func opencv() {
defer robotgo.FindBitmap(bit)
fmt.Print("find bitmap: ")
fmt.Println(robotgo.FindBitmap(bit))
bit0 := robotgo.CaptureScreen()
img := robotgo.ToImage(bit0)
bit1 := robotgo.CaptureScreen(10, 10, 30, 30)
img1 := robotgo.ToImage(bit1)
defer robotgo.FreeBitmapArr(bit0, bit1)
fmt.Print("gcv find image: ")
fmt.Println(gcv.FindImg(img1, img))
}
```

View File

@ -184,6 +184,7 @@ import (
"fmt"
"github.com/go-vgo/robotgo"
"github.com/vcaesar/imgo"
)
func main() {
@ -195,6 +196,13 @@ func main() {
sx, sy := robotgo.GetScreenSize()
fmt.Println("get screen size: ", sx, sy)
bit := robotgo.CaptureScreen(10, 10, 30, 30)
defer robotgo.FreeBitmap(bit)
robotgo.SaveBimap(bit, "test_1.png")
img := robotgo.ToImage(bit)
imgo.Save("test.png", img)
}
```
@ -246,6 +254,15 @@ func opencv() {
defer robotgo.FindBitmap(bit)
fmt.Print("find bitmap: ")
fmt.Println(robotgo.FindBitmap(bit))
bit0 := robotgo.CaptureScreen()
img := robotgo.ToImage(bit0)
bit1 := robotgo.CaptureScreen(10, 10, 30, 30)
img1 := robotgo.ToImage(bit1)
defer robotgo.FreeBitmapArr(bit0, bit1)
fmt.Print("gcv find image: ")
fmt.Println(gcv.FindImg(img1, img))
}
```

View File

@ -1215,12 +1215,19 @@ func Convert(opath, spath string, args ...int) {
SaveBitmap(bitmap, spath, mtype)
}
// FreeBitmap free and dealloc bitmap
// FreeBitmap free and dealloc the C bitmap
func FreeBitmap(bitmap C.MMBitmapRef) {
// C.destroyMMBitmap(bitmap)
C.bitmap_dealloc(bitmap)
}
// FreeBitmapArr free and dealloc the C bitmap array
func FreeBitmapArr(bit ...C.MMBitmapRef) {
for i := 0; i < len(bit); i++ {
FreeBitmap(bit[i])
}
}
// ReadBitmap returns false and sets error if |bitmap| is NULL
func ReadBitmap(bitmap C.MMBitmapRef) bool {
abool := C.bitmap_ready(bitmap)