add more bitmap examples code

This commit is contained in:
vcaesar 2021-09-15 11:23:24 -04:00
parent 9468b8fdde
commit cd0b69b3a1
2 changed files with 33 additions and 0 deletions

4
.gitignore vendored
View File

@ -90,3 +90,7 @@ examples/bitmap/test_IMG.png
examples/bitmap/imgToBitmap/test_01.png
examples/bitmap/imgToBitmap/test_002.jpeg
examples/bitmap/imgToBitmap/test_003.jpeg
examples/bitmap/imgToBitmap/test_1.png
examples/bitmap/imgToBitmap/test_2.jpeg
examples/bitmap/imgToBitmap/test.png
robot_img.png

View File

@ -1,14 +1,22 @@
//go:build go1.16
// +build go1.16
package main
import (
_ "embed"
"fmt"
"github.com/go-vgo/robotgo"
"github.com/vcaesar/imgo"
)
//go:embed test_01.png
var testPng []byte
func main() {
bit1 := robotgo.CaptureScreen(300, 300, 100, 100)
defer robotgo.FreeBitmap(bit1)
robotgo.SaveBitmap(bit1, "test_003.jpeg")
m1 := robotgo.ToImage(bit1)
@ -20,4 +28,25 @@ func main() {
bit2 := robotgo.ToCBitmap(robotgo.ImgToBitmap(m1))
robotgo.SaveBitmap(bit2, "test_002.jpeg")
test()
}
func test() {
bitmap := robotgo.CaptureScreen(10, 10, 10, 10)
defer robotgo.FreeBitmap(bitmap)
img := robotgo.ToImage(bitmap)
robotgo.SavePng(img, "test_1.png")
img1, _ := robotgo.ByteToImg(testPng)
robotgo.SaveJpeg(img1, "test_2.jpeg")
bit2 := robotgo.ToCBitmap(robotgo.ImgToBitmap(img))
fx, fy := robotgo.FindBitmap(bit2)
fmt.Println("FindBitmap------ ", fx, fy)
arr := robotgo.FindEveryBitmap(bit2)
fmt.Println("Find every bitmap: ", arr)
robotgo.SaveBitmap(bitmap, "test.png")
}