mirror of
https://github.com/go-vgo/robotgo.git
synced 2025-06-03 07:33:55 +00:00
Refactoring bitmap example code
This commit is contained in:
parent
f3a5747ac2
commit
85524fcf16
@ -19,19 +19,8 @@ import (
|
|||||||
// "go-vgo/robotgo"
|
// "go-vgo/robotgo"
|
||||||
)
|
)
|
||||||
|
|
||||||
func bitmap() {
|
func toBitmap(bmp robotgo.CBitmap) {
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
bitmap := robotgo.ToMMBitmapRef(bmp)
|
||||||
// Bitmap
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
|
||||||
|
|
||||||
// gets all of the screen
|
|
||||||
abitMap := robotgo.CaptureScreen()
|
|
||||||
fmt.Println("abitMap...", abitMap)
|
|
||||||
|
|
||||||
// gets part of the screen
|
|
||||||
bitmap := robotgo.CaptureScreen(100, 200, 30, 40)
|
|
||||||
defer robotgo.FreeBitmap(bitmap)
|
|
||||||
fmt.Println("CaptureScreen...", bitmap)
|
|
||||||
|
|
||||||
gbit := robotgo.ToBitmap(bitmap)
|
gbit := robotgo.ToBitmap(bitmap)
|
||||||
fmt.Println("go bitmap", gbit, gbit.Width)
|
fmt.Println("go bitmap", gbit, gbit.Width)
|
||||||
@ -40,6 +29,10 @@ func bitmap() {
|
|||||||
// defer robotgo.FreeBitmap(cbit)
|
// defer robotgo.FreeBitmap(cbit)
|
||||||
log.Println("cbit == bitmap: ", cbit == bitmap)
|
log.Println("cbit == bitmap: ", cbit == bitmap)
|
||||||
robotgo.SaveBitmap(cbit, "tocbitmap.png")
|
robotgo.SaveBitmap(cbit, "tocbitmap.png")
|
||||||
|
}
|
||||||
|
|
||||||
|
func findColor(bmp robotgo.CBitmap) {
|
||||||
|
bitmap := robotgo.ToMMBitmapRef(bmp)
|
||||||
|
|
||||||
// find the color in bitmap
|
// find the color in bitmap
|
||||||
color := robotgo.GetColor(bitmap, 1, 2)
|
color := robotgo.GetColor(bitmap, 1, 2)
|
||||||
@ -58,22 +51,10 @@ func bitmap() {
|
|||||||
fmt.Println("count...", cnt)
|
fmt.Println("count...", cnt)
|
||||||
cnt1 := robotgo.CountColorCS(0xAADCDC, 10, 20, 30, 40)
|
cnt1 := robotgo.CountColorCS(0xAADCDC, 10, 20, 30, 40)
|
||||||
fmt.Println("count...", cnt1)
|
fmt.Println("count...", cnt1)
|
||||||
|
}
|
||||||
|
|
||||||
count := robotgo.CountBitmap(abitMap, bitmap)
|
func bitmapTool(bmp robotgo.CBitmap) {
|
||||||
fmt.Println("count...", count)
|
bitmap := robotgo.ToMMBitmapRef(bmp)
|
||||||
|
|
||||||
bit := robotgo.CaptureScreen(1, 2, 40, 40)
|
|
||||||
defer robotgo.FreeBitmap(bit)
|
|
||||||
fmt.Println("CaptureScreen...", bit)
|
|
||||||
|
|
||||||
// searches for needle in bitmap
|
|
||||||
fx, fy := robotgo.FindBitmap(bit, bitmap)
|
|
||||||
fmt.Println("FindBitmap------", fx, fy)
|
|
||||||
// fx, fy := robotgo.FindBit(bitmap)
|
|
||||||
// fmt.Println("FindBitmap------", fx, fy)
|
|
||||||
|
|
||||||
fx, fy = robotgo.FindBitmap(bit)
|
|
||||||
fmt.Println("FindBitmap------", fx, fy)
|
|
||||||
|
|
||||||
// bitmap := robotgo.CaptureScreen(10, 20, 30, 40)
|
// bitmap := robotgo.CaptureScreen(10, 20, 30, 40)
|
||||||
abool := robotgo.PointInBounds(bitmap, 1, 2)
|
abool := robotgo.PointInBounds(bitmap, 1, 2)
|
||||||
@ -96,7 +77,9 @@ func bitmap() {
|
|||||||
// saves image to absolute filepath in the given format
|
// saves image to absolute filepath in the given format
|
||||||
robotgo.SaveBitmap(bitmap, "test.png")
|
robotgo.SaveBitmap(bitmap, "test.png")
|
||||||
robotgo.SaveBitmap(bitmap, "test31.tif", 1)
|
robotgo.SaveBitmap(bitmap, "test31.tif", 1)
|
||||||
|
}
|
||||||
|
|
||||||
|
func decode() {
|
||||||
img, name, err := robotgo.DecodeImg("test.png")
|
img, name, err := robotgo.DecodeImg("test.png")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Println("decode image ", err)
|
log.Println("decode image ", err)
|
||||||
@ -113,6 +96,66 @@ func bitmap() {
|
|||||||
|
|
||||||
// convert image
|
// convert image
|
||||||
robotgo.Convert("test.png", "test.tif")
|
robotgo.Convert("test.png", "test.tif")
|
||||||
|
}
|
||||||
|
|
||||||
|
func bitmapTest(bmp robotgo.CBitmap) {
|
||||||
|
bitmap := robotgo.ToMMBitmapRef(bmp)
|
||||||
|
|
||||||
|
bit := robotgo.CaptureScreen(1, 2, 40, 40)
|
||||||
|
defer robotgo.FreeBitmap(bit)
|
||||||
|
fmt.Println("CaptureScreen...", bit)
|
||||||
|
|
||||||
|
// searches for needle in bitmap
|
||||||
|
fx, fy := robotgo.FindBitmap(bit, bitmap)
|
||||||
|
fmt.Println("FindBitmap------", fx, fy)
|
||||||
|
|
||||||
|
// fx, fy := robotgo.FindBit(bitmap)
|
||||||
|
// fmt.Println("FindBitmap------", fx, fy)
|
||||||
|
|
||||||
|
fx, fy = robotgo.FindBitmap(bit)
|
||||||
|
fmt.Println("FindBitmap------", fx, fy)
|
||||||
|
}
|
||||||
|
|
||||||
|
func bitmap() {
|
||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
// Bitmap
|
||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
// gets all of the screen
|
||||||
|
abitMap := robotgo.CaptureScreen()
|
||||||
|
fmt.Println("abitMap...", abitMap)
|
||||||
|
|
||||||
|
// gets part of the screen
|
||||||
|
bitmap := robotgo.CaptureScreen(100, 200, 30, 30)
|
||||||
|
defer robotgo.FreeBitmap(bitmap)
|
||||||
|
fmt.Println("CaptureScreen...", bitmap)
|
||||||
|
|
||||||
|
cbit := robotgo.CBitmap(bitmap)
|
||||||
|
toBitmap(cbit)
|
||||||
|
|
||||||
|
findColor(cbit)
|
||||||
|
|
||||||
|
count := robotgo.CountBitmap(abitMap, bitmap)
|
||||||
|
fmt.Println("count...", count)
|
||||||
|
|
||||||
|
bitmapTest(cbit)
|
||||||
|
findBitmap(cbit)
|
||||||
|
|
||||||
|
bitmapTool(cbit)
|
||||||
|
|
||||||
|
decode()
|
||||||
|
|
||||||
|
// free the bitmap
|
||||||
|
robotgo.FreeBitmap(abitMap)
|
||||||
|
// robotgo.FreeBitmap(bitmap)
|
||||||
|
}
|
||||||
|
|
||||||
|
func findBitmap(bmp robotgo.CBitmap) {
|
||||||
|
fx, fy := robotgo.FindBitmap(robotgo.ToMMBitmapRef(bmp))
|
||||||
|
fmt.Println("findBitmap: ", fx, fy)
|
||||||
|
|
||||||
|
fx, fy = robotgo.FindCBitmap(bmp)
|
||||||
|
fmt.Println("findCBitmap: ", fx, fy)
|
||||||
|
|
||||||
// open image bitmap
|
// open image bitmap
|
||||||
openbit := robotgo.OpenBitmap("test.tif")
|
openbit := robotgo.OpenBitmap("test.tif")
|
||||||
@ -123,10 +166,6 @@ func bitmap() {
|
|||||||
|
|
||||||
fx, fy = robotgo.FindPic("test.tif")
|
fx, fy = robotgo.FindPic("test.tif")
|
||||||
fmt.Println("FindPic------", fx, fy)
|
fmt.Println("FindPic------", fx, fy)
|
||||||
|
|
||||||
// free the bitmap
|
|
||||||
robotgo.FreeBitmap(abitMap)
|
|
||||||
// robotgo.FreeBitmap(bitmap)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
|
Loading…
Reference in New Issue
Block a user