Merge pull request #376 from go-vgo/bitmap-pr

add free bitmap array support and Update README.md
This commit is contained in:
Evans 2021-10-12 12:16:24 -04:00 committed by GitHub
commit 7a92ff967a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 54 additions and 7 deletions

View File

@ -132,11 +132,12 @@ func main() {
robotgo.ScrollMouse(10, "up")
robotgo.Scroll(100, 200)
robotgo.MoveMouse(10, 10)
robotgo.Move(10, 10)
robotgo.Drag(10, 10)
robotgo.MouseClick("left", true)
robotgo.MoveMouseSmooth(100, 200, 1.0, 100.0)
robotgo.Click("left", true)
robotgo.MoveSmooth(100, 200, 1.0, 100.0)
robotgo.MouseToggle("up")
}
```
@ -169,6 +170,8 @@ func main() {
arr := []string{"alt", "command"}
robotgo.KeyTap("i", arr)
robotgo.KeyToggle("a", "down")
robotgo.WriteAll("Test")
text, err := robotgo.ReadAll()
if err == nil {
@ -186,6 +189,7 @@ import (
"fmt"
"github.com/go-vgo/robotgo"
"github.com/vcaesar/imgo"
)
func main() {
@ -197,6 +201,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.SaveBitmap(bit, "test_1.png")
img := robotgo.ToImage(bit)
imgo.Save("test.png", img)
}
```
@ -248,6 +259,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

@ -130,11 +130,12 @@ func main() {
robotgo.ScrollMouse(10, "up")
robotgo.Scroll(100, 200)
robotgo.MoveMouse(10, 10)
robotgo.Move(10, 10)
robotgo.Drag(10, 10)
robotgo.MouseClick("left", true)
robotgo.MoveMouseSmooth(100, 200, 1.0, 100.0)
robotgo.Click("left", true)
robotgo.MoveSmooth(100, 200, 1.0, 100.0)
robotgo.MouseToggle("up")
}
```
@ -167,6 +168,8 @@ func main() {
arr := []string{"alt", "command"}
robotgo.KeyTap("i", arr)
robotgo.KeyToggle("a", "down")
robotgo.WriteAll("テストする")
text, err := robotgo.ReadAll()
if err == nil {
@ -184,6 +187,7 @@ import (
"fmt"
"github.com/go-vgo/robotgo"
"github.com/vcaesar/imgo"
)
func main() {
@ -195,6 +199,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.SaveBitmap(bit, "test_1.png")
img := robotgo.ToImage(bit)
imgo.Save("test.png", img)
}
```
@ -246,6 +257,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)