-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathmain.go
185 lines (140 loc) · 4.5 KB
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
// Copyright 2016 The go-vgo Project Developers. See the COPYRIGHT
// file at the top-level directory of this distribution and at
// https://github.com/go-vgo/robotgo/blob/master/LICENSE
//
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
// option. This file may not be copied, modified, or distributed
// except according to those terms.
package main
import (
"fmt"
"log"
"github.com/go-vgo/robotgo"
"github.com/vcaesar/bitmap"
"github.com/vcaesar/imgo"
)
func toBitmap(bmp robotgo.CBitmap) {
img := robotgo.ToImage(bmp)
fmt.Println("img: ", img)
imgo.SaveToPNG("test_IMG.png", img)
gbit := robotgo.ToBitmap(bmp)
fmt.Println("go bitmap", gbit, gbit.Width)
cbit := robotgo.ToCBitmap(gbit)
// defer robotgo.FreeBitmap(cbit)
log.Println("cbit == bitmap: ", cbit == bmp)
}
// find color
func findColor(bmp robotgo.CBitmap) {
// find the color in bitmap
color := bitmap.GetColor(bmp, 1, 2)
fmt.Println("color...", color)
cx, cy := bitmap.FindColor(robotgo.CHex(color), bmp, 1.0)
fmt.Println("pos...", cx, cy)
cx, cy = bitmap.FindColor(robotgo.CHex(color))
fmt.Println("pos...", cx, cy)
cx, cy = bitmap.FindColor(0xAADCDC, bmp)
fmt.Println("pos...", cx, cy)
cx, cy = bitmap.FindColor(0xAADCDC, nil, 0.1)
fmt.Println("pos...", cx, cy)
cx, cy = bitmap.FindColorCS(0xAADCDC, 388, 179, 300, 300)
fmt.Println("pos...", cx, cy)
cnt := bitmap.CountColor(0xAADCDC, bmp)
fmt.Println("count...", cnt)
cnt1 := bitmap.CountColorCS(0xAADCDC, 10, 20, 30, 40)
fmt.Println("count...", cnt1)
arr := bitmap.FindAllColor(0xAADCDC)
fmt.Println("find all color: ", arr)
for i := 0; i < len(arr); i++ {
fmt.Println("pos is: ", arr[i].X, arr[i].Y)
}
}
func bitmapString(bmp robotgo.CBitmap) {
// creates bitmap from string by bitmap
bitstr := bitmap.Tostring(bmp)
fmt.Println("bitstr...", bitstr)
sbitmap := bitmap.FromStr(bitstr)
fmt.Println("bitmap str...", sbitmap)
bitmap.Save(sbitmap, "teststr.png")
}
func bitmapTool(bmp robotgo.CBitmap) {
abool := bitmap.PointInBounds(bmp, 1, 2)
fmt.Println("point in bounds...", abool)
// returns new bitmap object created from a portion of another
bitpos := bitmap.GetPortion(bmp, 10, 10, 11, 10)
fmt.Println(bitpos)
// saves image to absolute filepath in the given format
bitmap.Save(bmp, "test.png")
}
func decode() {
img, name, err := robotgo.DecodeImg("test.png")
if err != nil {
log.Println("decode image ", err)
}
fmt.Println("decode test.png", img, name)
byt, _ := robotgo.OpenImg("test.png")
imgo.SaveByte("test2.png", byt)
w, h := bitmap.GetSize("test.png")
fmt.Println("image width and hight ", w, h)
w, h, _ = imgo.GetSize("test.png")
fmt.Println("image width and hight ", w, h)
// convert image
bitmap.Convert("test.png", "test.tif")
}
func bitmapTest(bmp robotgo.CBitmap) {
bit := robotgo.CaptureScreen(1, 2, 40, 40)
defer robotgo.FreeBitmap(bit)
fmt.Println("CaptureScreen...", bit)
// searches for needle in bitmap
fx, fy := bitmap.Find(bit, bmp)
fmt.Println("FindBitmap------", fx, fy)
fx, fy = bitmap.Find(bit)
fmt.Println("FindBitmap------", fx, fy)
fx, fy = bitmap.Find(bit, nil, 0.2)
fmt.Println("find bitmap: ", fx, fy)
fx, fy = bitmap.Find(bit, bmp, 0.3)
fmt.Println("find bitmap: ", fx, fy)
}
func findBitmap(bmp robotgo.CBitmap) {
fx, fy := bitmap.Find(bmp)
fmt.Println("findBitmap: ", fx, fy)
// open image bitmap
openbit := bitmap.Open("test.tif")
fmt.Println("openBitmap...", openbit)
fx, fy = bitmap.Find(openbit)
fmt.Println("FindBitmap------", fx, fy)
fx, fy = bitmap.FindPic("test.tif")
fmt.Println("FindPic------", fx, fy)
arr := bitmap.FindAll(openbit)
fmt.Println("find all bitmap: ", arr)
for i := 0; i < len(arr); i++ {
fmt.Println("pos is: ", arr[i].X, arr[i].Y)
}
}
func bitmap1() {
////////////////////////////////////////////////////////////////////////////////
// Bitmap
////////////////////////////////////////////////////////////////////////////////
// gets all of the screen
abitMap := robotgo.CaptureScreen()
fmt.Println("abitMap...", abitMap)
// gets part of the screen
cbit := robotgo.CaptureScreen(100, 200, 30, 30)
defer robotgo.FreeBitmap(cbit)
fmt.Println("CaptureScreen...", cbit)
toBitmap(cbit)
findColor(cbit)
count := bitmap.Count(abitMap, cbit)
fmt.Println("count...", count)
bitmapTest(cbit)
findBitmap(cbit)
bitmapString(cbit)
bitmapTool(cbit)
decode()
// free the bitmap
robotgo.FreeBitmap(abitMap)
}
func main() {
bitmap1()
}