mirror of
https://github.com/go-vgo/robotgo.git
synced 2025-05-29 21:43:55 +00:00
Remove bitmap
This commit is contained in:
parent
5afcb0af9c
commit
6f4ab42757
@ -10,7 +10,7 @@ addons:
|
||||
apt:
|
||||
packages:
|
||||
- libx11-dev xorg-dev
|
||||
- libxtst-dev libpng++-dev
|
||||
# - libxtst-dev libpng++-dev
|
||||
- xcb libxcb-xkb-dev x11-xkb-utils libx11-xcb-dev libxkbcommon-x11-dev
|
||||
# - libusb-dev
|
||||
- libxkbcommon-dev
|
||||
|
24
README.md
24
README.md
@ -37,31 +37,22 @@ This is a work in progress.
|
||||
|
||||
## Requirements:
|
||||
|
||||
Now, Please make sure Golang, GCC, zlib and libpng is installed correctly before installing RobotGo.
|
||||
|
||||
If you do not need bitmap, you can switch to the robot branch, where there is no zlib and libpng dependency.
|
||||
Now, Please make sure Golang, GCC is installed correctly before installing RobotGo.
|
||||
|
||||
### ALL:
|
||||
```
|
||||
Golang
|
||||
GCC
|
||||
zlib & libpng (bitmap)
|
||||
```
|
||||
#### For Mac OS X:
|
||||
Xcode Command Line Tools
|
||||
```
|
||||
brew install libpng
|
||||
brew install homebrew/dupes/zlib
|
||||
Xcode Command Line Tools
|
||||
```
|
||||
#### For Windows:
|
||||
```
|
||||
MinGW or other GCC
|
||||
|
||||
zlib & libpng (bitmap need it.)
|
||||
```
|
||||
##### [Zlib & libpng Windows32 GCC's Course](https://github.com/go-vgo/Mingw32)
|
||||
|
||||
##### [Download include zlib & libpng Windows64 GCC](https://github.com/go-vgo/Mingw)
|
||||
|
||||
#### For everything else:
|
||||
```
|
||||
@ -79,8 +70,7 @@ xcb, xkb, libxkbcommon
|
||||
sudo apt-get install gcc libc6-dev
|
||||
|
||||
sudo apt-get install libx11-dev
|
||||
sudo apt-get install xorg-dev
|
||||
sudo apt-get install libxtst-dev libpng++-dev
|
||||
sudo apt-get install xorg-dev
|
||||
|
||||
sudo apt-get install xcb libxcb-xkb-dev x11-xkb-utils libx11-xcb-dev libxkbcommon-x11-dev
|
||||
sudo apt-get install libxkbcommon-dev
|
||||
@ -94,8 +84,6 @@ sudo apt-get install xclip
|
||||
```yml
|
||||
sudo dnf install libxkbcommon-devel libXtst-devel libxkbcommon-x11-devel xorg-x11-xkb-utils-devel
|
||||
|
||||
sudo dnf install libpng-devel
|
||||
|
||||
sudo dnf install xsel
|
||||
sudo dnf install xclip
|
||||
```
|
||||
@ -106,8 +94,6 @@ go get github.com/go-vgo/robotgo
|
||||
```
|
||||
It's that easy!
|
||||
|
||||
png.h: No such file or directory? Please see [issues/47](https://github.com/go-vgo/robotgo/issues/47).
|
||||
|
||||
## Update:
|
||||
```
|
||||
go get -u github.com/go-vgo/robotgo
|
||||
@ -177,7 +163,7 @@ func main() {
|
||||
}
|
||||
```
|
||||
|
||||
#### [Bitmap](https://github.com/go-vgo/robotgo/blob/master/examples/bitmap/mian.go)
|
||||
<!-- #### [Bitmap](https://github.com/go-vgo/robotgo/blob/master/examples/bitmap/mian.go)
|
||||
|
||||
```Go
|
||||
package main
|
||||
@ -197,7 +183,7 @@ func main() {
|
||||
|
||||
robotgo.SaveBitmap(bitmap, "test.png")
|
||||
}
|
||||
```
|
||||
``` -->
|
||||
|
||||
#### [Event](https://github.com/go-vgo/robotgo/blob/master/examples/event/main.go)
|
||||
|
||||
|
27
README_zh.md
27
README_zh.md
@ -35,30 +35,21 @@ QQ 群: 595877611
|
||||
## Requirements:
|
||||
环境要求:
|
||||
|
||||
在安装 RobotGo 之前, 请确保 Golang、GCC、zlib 和 libpng 被正确安装
|
||||
|
||||
如果你不需要bitmap, 你可以切换到robot分支, 那里没有 zlib 和 libpng 依赖
|
||||
在安装 RobotGo 之前, 请确保 Golang、GCC 被正确安装
|
||||
|
||||
### ALL:
|
||||
```
|
||||
Golang
|
||||
GCC
|
||||
zlib & libpng (bitmap)
|
||||
```
|
||||
#### For Mac OS X:
|
||||
Xcode Command Line Tools
|
||||
```
|
||||
brew install libpng
|
||||
brew install homebrew/dupes/zlib
|
||||
Xcode Command Line Tools
|
||||
```
|
||||
#### For Windows:
|
||||
```
|
||||
MinGW or other GCC
|
||||
|
||||
zlib & libpng (bitmap 依赖)
|
||||
```
|
||||
##### [Zlib & libpng Windows32 GCC 教程](https://github.com/go-vgo/Mingw32)
|
||||
##### [下载包含 zlib 和 libpng 的 64位 MinGW](https://github.com/go-vgo/Mingw)
|
||||
|
||||
#### For everything else (Linux 等其他系统):
|
||||
```
|
||||
@ -76,9 +67,7 @@ xcb, xkb, libxkbcommon
|
||||
sudo apt-get install gcc libc6-dev
|
||||
|
||||
sudo apt-get install libx11-dev
|
||||
sudo apt-get install xorg-dev
|
||||
sudo apt-get install libxtst-dev libpng++-dev
|
||||
|
||||
sudo apt-get install xorg-dev
|
||||
|
||||
sudo apt-get install xcb libxcb-xkb-dev x11-xkb-utils libx11-xcb-dev libxkbcommon-x11-dev
|
||||
sudo apt-get install libxkbcommon-dev
|
||||
@ -93,8 +82,6 @@ sudo apt-get install xclip
|
||||
```yml
|
||||
sudo dnf install libxkbcommon-devel libXtst-devel libxkbcommon-x11-devel xorg-x11-xkb-utils-devel
|
||||
|
||||
sudo dnf install libpng-devel
|
||||
|
||||
sudo dnf install xsel
|
||||
sudo dnf install xclip
|
||||
```
|
||||
@ -102,9 +89,7 @@ sudo dnf install xclip
|
||||
```
|
||||
go get github.com/go-vgo/robotgo
|
||||
```
|
||||
It's that easy!
|
||||
|
||||
png.h: No such file or directory? Please see [issues/47](https://github.com/go-vgo/robotgo/issues/47).
|
||||
It's that easy!
|
||||
|
||||
## Update:
|
||||
```
|
||||
@ -175,7 +160,7 @@ func main() {
|
||||
}
|
||||
```
|
||||
|
||||
#### [位图](https://github.com/go-vgo/robotgo/blob/master/examples/bitmap/mian.go)
|
||||
<!-- #### [位图](https://github.com/go-vgo/robotgo/blob/master/examples/bitmap/mian.go)
|
||||
|
||||
```Go
|
||||
package main
|
||||
@ -195,7 +180,7 @@ func main() {
|
||||
|
||||
robotgo.SaveBitmap(bitmap, "test.png")
|
||||
}
|
||||
```
|
||||
``` -->
|
||||
|
||||
#### [事件](https://github.com/go-vgo/robotgo/blob/master/examples/event/main.go)
|
||||
|
||||
|
@ -12,7 +12,7 @@ dependencies:
|
||||
# - sudo apt-get install libghc6-x11-dev
|
||||
# - sudo apt-get install libgl1-mesa-swx11-dev
|
||||
- sudo apt-get install xorg-dev
|
||||
- sudo apt-get install libxtst-dev libpng++-dev
|
||||
# - sudo apt-get install libxtst-dev libpng++-dev
|
||||
# Event:
|
||||
- sudo apt-get install xcb libxcb-xkb-dev x11-xkb-utils libx11-xcb-dev libxkbcommon-x11-dev
|
||||
- sudo apt-get install libxkbcommon-dev
|
||||
|
@ -30,44 +30,4 @@ func main() {
|
||||
bitmap := robotgo.CaptureScreen(100, 200, 30, 40)
|
||||
fmt.Println("CaptureScreen...", bitmap)
|
||||
|
||||
// searches for needle in bitmap
|
||||
fx, fy := robotgo.FindBit(bitmap)
|
||||
fmt.Println("FindBitmap------", fx, fy)
|
||||
|
||||
color := robotgo.GetColor(bitmap, 1, 2)
|
||||
fmt.Println("color...", color)
|
||||
cx, cy := robotgo.FindColor(bitmap, color, 1.0)
|
||||
fmt.Println("pos...", cx, cy)
|
||||
|
||||
bit := robotgo.CaptureScreen(1, 2, 40, 40)
|
||||
fmt.Println("CaptureScreen...", bit)
|
||||
fx, fy = robotgo.FindBitmap(bit)
|
||||
fmt.Println("FindBitmap------", fx, fy)
|
||||
fx, fy = robotgo.FindBitmap(bit, bitmap)
|
||||
fmt.Println("FindBitmap------", fx, fy)
|
||||
|
||||
// returns new bitmap object created from a portion of another
|
||||
bitpos := robotgo.GetPortion(bitmap, 10, 10, 11, 10)
|
||||
fmt.Println(bitpos)
|
||||
|
||||
// creates bitmap from string by bitmap
|
||||
bitstr := robotgo.TostringBitmap(bitmap)
|
||||
fmt.Println("bitstr...", bitstr)
|
||||
|
||||
// sbitmap := robotgo.BitmapFromstring(bitstr, 2)
|
||||
// fmt.Println("...", sbitmap)
|
||||
|
||||
// saves image to absolute filepath in the given format
|
||||
robotgo.SaveBitmap(bitmap, "test.png")
|
||||
robotgo.SaveBitmap(bitmap, "test31.tif", 1)
|
||||
|
||||
// convert image
|
||||
robotgo.Convert("test.png", "test.tif")
|
||||
|
||||
// open image bitmap
|
||||
openbit := robotgo.OpenBitmap("test.tif")
|
||||
fmt.Println("openBitmap...", openbit)
|
||||
|
||||
fx, fy = robotgo.FindBitmap(openbit)
|
||||
fmt.Println("FindBitmap------", fx, fy)
|
||||
}
|
||||
|
@ -127,60 +127,7 @@ func screen() {
|
||||
|
||||
}
|
||||
|
||||
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, 40)
|
||||
fmt.Println("CaptureScreen...", bitmap)
|
||||
|
||||
// searches for needle in bitmap
|
||||
fx, fy := robotgo.FindBit(bitmap)
|
||||
fmt.Println("FindBitmap------", fx, fy)
|
||||
|
||||
color := robotgo.GetColor(bitmap, 1, 2)
|
||||
fmt.Println("color...", color)
|
||||
cx, cy := robotgo.FindColor(bitmap, color, 1.0)
|
||||
fmt.Println("pos...", cx, cy)
|
||||
|
||||
bit := robotgo.CaptureScreen(1, 2, 40, 40)
|
||||
fmt.Println("CaptureScreen...", bit)
|
||||
fx, fy = robotgo.FindBitmap(bit)
|
||||
fmt.Println("FindBitmap------", fx, fy)
|
||||
fx, fy = robotgo.FindBitmap(bit, bitmap)
|
||||
fmt.Println("FindBitmap------", fx, fy)
|
||||
|
||||
// returns new bitmap object created from a portion of another
|
||||
bitpos := robotgo.GetPortion(bitmap, 10, 10, 11, 10)
|
||||
fmt.Println(bitpos)
|
||||
|
||||
// creates bitmap from string by bitmap
|
||||
bitstr := robotgo.TostringBitmap(bitmap)
|
||||
fmt.Println("bitstr...", bitstr)
|
||||
|
||||
// sbitmap := robotgo.BitmapFromstring(bitstr, 2)
|
||||
// fmt.Println("...", sbitmap)
|
||||
|
||||
// saves image to absolute filepath in the given format
|
||||
robotgo.SaveBitmap(bitmap, "test.png")
|
||||
robotgo.SaveBitmap(bitmap, "test31.tif", 1)
|
||||
|
||||
// convert image
|
||||
robotgo.Convert("test.png", "test.tif")
|
||||
|
||||
// open image bitmap
|
||||
openbit := robotgo.OpenBitmap("test.tif")
|
||||
fmt.Println("openBitmap...", openbit)
|
||||
|
||||
fx, fy = robotgo.FindBitmap(openbit)
|
||||
fmt.Println("FindBitmap------", fx, fy)
|
||||
}
|
||||
|
||||
func event() {
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
@ -302,8 +249,7 @@ func main() {
|
||||
mouse()
|
||||
// Read the screen
|
||||
screen()
|
||||
// Bitmap and image processing
|
||||
bitmap()
|
||||
|
||||
// Global event listener
|
||||
event()
|
||||
// Window Handle and progress
|
||||
|
188
robotgo.go
188
robotgo.go
@ -25,18 +25,18 @@ package robotgo
|
||||
/*
|
||||
//#if defined(IS_MACOSX)
|
||||
#cgo darwin CFLAGS: -x objective-c -Wno-deprecated-declarations -I/usr/local/opt/libpng/include -I/usr/local/opt/zlib/include
|
||||
#cgo darwin LDFLAGS: -framework Cocoa -framework OpenGL -framework IOKit -framework Carbon -framework CoreFoundation -L/usr/local/opt/libpng/lib -lpng -L/usr/local/opt/zlib/lib -lz
|
||||
#cgo darwin LDFLAGS: -framework Cocoa -framework OpenGL -framework IOKit -framework Carbon -framework CoreFoundation
|
||||
//#elif defined(USE_X11)
|
||||
// drop -std=c11
|
||||
#cgo linux CFLAGS:-I/usr/src
|
||||
#cgo linux LDFLAGS:-L/usr/src -lpng -lz -lX11 -lXtst -lX11-xcb -lxcb -lxcb-xkb -lxkbcommon -lxkbcommon-x11 -lm
|
||||
#cgo linux LDFLAGS:-L/usr/src -lX11 -lXtst -lX11-xcb -lxcb -lxcb-xkb -lxkbcommon -lxkbcommon-x11 -lm
|
||||
//#endif
|
||||
#cgo windows LDFLAGS: -lgdi32 -luser32 -lpng -lz
|
||||
#cgo windows LDFLAGS: -lgdi32 -luser32
|
||||
//#include <AppKit/NSEvent.h>
|
||||
#include "screen/goScreen.h"
|
||||
#include "mouse/goMouse.h"
|
||||
#include "key/goKey.h"
|
||||
#include "bitmap/goBitmap.h"
|
||||
// // // // // #include "bitmap/goBitmap.h"
|
||||
#include "event/goEvent.h"
|
||||
#include "window/goWindow.h"
|
||||
*/
|
||||
@ -571,187 +571,7 @@ func SetKeyboardDelay(x int) {
|
||||
|______/ |__| |__| |__| |__| /__/ \__\ | _|
|
||||
*/
|
||||
|
||||
// FindBitmap find the bitmap
|
||||
func FindBitmap(args ...interface{}) (int, int) {
|
||||
var (
|
||||
bit C.MMBitmapRef
|
||||
sbit C.MMBitmapRef
|
||||
tolerance C.float
|
||||
)
|
||||
|
||||
bit = args[0].(C.MMBitmapRef)
|
||||
if len(args) > 1 {
|
||||
sbit = args[1].(C.MMBitmapRef)
|
||||
} else {
|
||||
sbit = CaptureScreen()
|
||||
}
|
||||
|
||||
if len(args) > 2 {
|
||||
tolerance = C.float(args[2].(float32))
|
||||
} else {
|
||||
tolerance = 0.5
|
||||
}
|
||||
|
||||
pos := C.bitmap_find_bitmap(bit, sbit, tolerance)
|
||||
// fmt.Println("pos----", pos)
|
||||
return int(pos.x), int(pos.y)
|
||||
}
|
||||
|
||||
// FindBit find the bitmap
|
||||
func FindBit(args ...interface{}) (int, int) {
|
||||
var bit C.MMBitmapRef
|
||||
bit = args[0].(C.MMBitmapRef)
|
||||
|
||||
var rect C.MMRect
|
||||
Try(func() {
|
||||
rect.origin.x = C.size_t(args[1].(int))
|
||||
rect.origin.y = C.size_t(args[2].(int))
|
||||
rect.size.width = C.size_t(args[3].(int))
|
||||
rect.size.height = C.size_t(args[4].(int))
|
||||
}, func(e interface{}) {
|
||||
// fmt.Println("err:::", e)
|
||||
// rect.origin.x = x
|
||||
// rect.origin.y = y
|
||||
// rect.size.width = w
|
||||
// rect.size.height = h
|
||||
})
|
||||
|
||||
pos := C.aFindBitmap(bit, rect)
|
||||
// fmt.Println("pos----", pos)
|
||||
return int(pos.x), int(pos.y)
|
||||
}
|
||||
|
||||
// OpenBitmap open the bitmap
|
||||
func OpenBitmap(args ...interface{}) C.MMBitmapRef {
|
||||
path := C.CString(args[0].(string))
|
||||
var mtype C.uint16_t
|
||||
Try(func() {
|
||||
mtype = C.uint16_t(args[1].(int))
|
||||
}, func(e interface{}) {
|
||||
// fmt.Println("err:::", e)
|
||||
mtype = 1
|
||||
})
|
||||
bit := C.bitmap_open(path, mtype)
|
||||
defer C.free(unsafe.Pointer(path))
|
||||
// fmt.Println("opening...", bit)
|
||||
return bit
|
||||
// defer C.free(unsafe.Pointer(path))
|
||||
}
|
||||
|
||||
// SaveBitmap save the bitmap
|
||||
func SaveBitmap(args ...interface{}) string {
|
||||
var mtype C.uint16_t
|
||||
Try(func() {
|
||||
mtype = C.uint16_t(args[2].(int))
|
||||
}, func(e interface{}) {
|
||||
// fmt.Println("err:::", e)
|
||||
mtype = 1
|
||||
})
|
||||
|
||||
path := C.CString(args[1].(string))
|
||||
savebit := C.bitmap_save(args[0].(C.MMBitmapRef), path, mtype)
|
||||
// fmt.Println("saved...", savebit)
|
||||
// return bit
|
||||
defer C.free(unsafe.Pointer(path))
|
||||
|
||||
return C.GoString(savebit)
|
||||
}
|
||||
|
||||
// func SaveBitmap(bit C.MMBitmapRef, gpath string, mtype C.MMImageType) {
|
||||
// path := C.CString(gpath)
|
||||
// savebit := C.aSaveBitmap(bit, path, mtype)
|
||||
// fmt.Println("saving...", savebit)
|
||||
// // return bit
|
||||
// // defer C.free(unsafe.Pointer(path))
|
||||
// }
|
||||
|
||||
// TostringBitmap tostring bitmap
|
||||
func TostringBitmap(bit C.MMBitmapRef) *C.char {
|
||||
// str_bit := C.aTostringBitmap(bit)
|
||||
strBit := C.tostring_Bitmap(bit)
|
||||
// fmt.Println("...", str_bit)
|
||||
// return str_bit
|
||||
return strBit
|
||||
}
|
||||
|
||||
// GetPortion get portion
|
||||
func GetPortion(bit C.MMBitmapRef, x, y, w, h C.size_t) C.MMBitmapRef {
|
||||
var rect C.MMRect
|
||||
rect.origin.x = x
|
||||
rect.origin.y = y
|
||||
rect.size.width = w
|
||||
rect.size.height = h
|
||||
|
||||
pos := C.get_Portion(bit, rect)
|
||||
return pos
|
||||
}
|
||||
|
||||
// Convert convert bitmap
|
||||
func Convert(args ...interface{}) {
|
||||
var mtype int
|
||||
Try(func() {
|
||||
mtype = args[2].(int)
|
||||
}, func(e interface{}) {
|
||||
// fmt.Println("err:::", e)
|
||||
mtype = 1
|
||||
})
|
||||
//C.CString()
|
||||
opath := args[0].(string)
|
||||
spath := args[1].(string)
|
||||
bitmap := OpenBitmap(opath)
|
||||
// fmt.Println("a----", bit_map)
|
||||
SaveBitmap(bitmap, spath, mtype)
|
||||
}
|
||||
|
||||
// FreeBitmap free and dealloc bitmap
|
||||
func FreeBitmap(bitmap C.MMBitmapRef) {
|
||||
// C.destroyMMBitmap(bitmap)
|
||||
C.bitmap_dealloc(bitmap)
|
||||
}
|
||||
|
||||
// ReadBitmap returns false and sets error if |bitmap| is NULL
|
||||
func ReadBitmap(bitmap C.MMBitmapRef) bool {
|
||||
abool := C.bitmap_ready(bitmap)
|
||||
gbool := bool(abool)
|
||||
return gbool
|
||||
}
|
||||
|
||||
// CopyBitpb copy bitmap to pasteboard
|
||||
func CopyBitpb(bitmap C.MMBitmapRef) bool {
|
||||
abool := C.bitmap_copy_to_pboard(bitmap)
|
||||
gbool := bool(abool)
|
||||
return gbool
|
||||
}
|
||||
|
||||
// DeepCopyBit deep copy bitmap
|
||||
func DeepCopyBit(bitmap C.MMBitmapRef) C.MMBitmapRef {
|
||||
bit := C.bitmap_deepcopy(bitmap)
|
||||
return bit
|
||||
}
|
||||
|
||||
// GetColor get bitmap color
|
||||
func GetColor(bitmap C.MMBitmapRef, x, y int) C.MMRGBHex {
|
||||
color := C.bitmap_get_color(bitmap, C.size_t(x), C.size_t(y))
|
||||
|
||||
return color
|
||||
}
|
||||
|
||||
// FindColor find bitmap color
|
||||
func FindColor(bitmap C.MMBitmapRef, color C.MMRGBHex, args ...float32) (int, int) {
|
||||
var tolerance C.float
|
||||
|
||||
if len(args) > 2 {
|
||||
tolerance = C.float(args[2])
|
||||
} else {
|
||||
tolerance = 0.5
|
||||
}
|
||||
|
||||
pos := C.bitmap_find_color(bitmap, color, tolerance)
|
||||
x := int(pos.x)
|
||||
y := int(pos.y)
|
||||
|
||||
return x, y
|
||||
}
|
||||
|
||||
/*
|
||||
___________ ____ _______ .__ __. .___________.
|
||||
|
@ -53,11 +53,6 @@ func aRobotgo() {
|
||||
bitmap := robotgo.CaptureScreen(10, 20, 30, 40)
|
||||
fmt.Println("...", bitmap)
|
||||
|
||||
fx, fy := robotgo.FindBitmap(bitmap)
|
||||
fmt.Println("FindBitmap------", fx, fy)
|
||||
|
||||
robotgo.SaveBitmap(bitmap, "test.png", 1)
|
||||
|
||||
// robotgo.MouseClick()
|
||||
robotgo.ScrollMouse(10, "up")
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user