Skip to content

Commit

Permalink
add more image function support
Browse files Browse the repository at this point in the history
  • Loading branch information
vcaesar committed Sep 24, 2021
1 parent 4dcdfe7 commit 2768d08
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 13 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
<!-- [![Release](https://github-release-version.herokuapp.com/github/go-vgo/robotgo/release.svg?style=flat)](https://github.com/go-vgo/robotgo/releases/latest) -->
<!-- <a href="https://github.com/go-vgo/robotgo/releases"><img src="https://img.shields.io/badge/%20version%20-%206.0.0%20-blue.svg?style=flat-square" alt="Releases"></a> -->

>Golang Desktop Automation. Control the mouse, keyboard, bitmap and image, read the screen, process, Window Handle and global event listener.
> Golang Desktop Automation. Control the mouse, keyboard, bitmap and image, read the screen, process, Window Handle and global event listener.
RobotGo supports Mac, Windows, and Linux(X11); and robotgo supports arm64 and x86-amd64.

Expand Down
2 changes: 1 addition & 1 deletion README_zh.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
[![GitHub release](https://img.shields.io/github/release/go-vgo/robotgo.svg)](https://github.com/go-vgo/robotgo/releases/latest)
[![Join the chat at https://gitter.im/go-vgo/robotgo](https://badges.gitter.im/Join%20Chat.svg)](https://gitter.im/go-vgo/robotgo?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)

>Golang 跨平台自动化系统,控制键盘、鼠标、位图、图像、读取屏幕,进程、窗口句柄以及全局事件监听
> Golang 跨平台自动化系统,控制键盘、鼠标、位图、图像、读取屏幕,进程、窗口句柄以及全局事件监听
RobotGo 支持 Mac, Windows, and Linux(X11).

Expand Down
3 changes: 2 additions & 1 deletion examples/bitmap/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ func toBitmap(bmp robotgo.CBitmap) {
robotgo.SaveBitmap(cbit, "tocbitmap.png")
}

// find color
func findColor(bmp robotgo.CBitmap) {
bitmap := robotgo.ToMMBitmapRef(bmp)

Expand Down Expand Up @@ -105,7 +106,7 @@ func decode() {
fmt.Println("decode test.png", img, name)

byt, _ := robotgo.OpenImg("test.png")
imgo.Save("test2.png", byt)
imgo.SaveByte("test2.png", byt)

w, h := robotgo.GetImgSize("test.png")
fmt.Println("image width and hight ", w, h)
Expand Down
4 changes: 2 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ require (
github.com/robotn/xgb v0.0.0-20190912153532-2cb92d044934
github.com/robotn/xgbutil v0.0.0-20190912154524-c861d6f87770
github.com/vcaesar/gops v0.21.2
github.com/vcaesar/imgo v0.20.0
github.com/vcaesar/tt v0.11.0
github.com/vcaesar/imgo v0.30.0
github.com/vcaesar/tt v0.20.0
golang.org/x/image v0.0.0-20210628002857-a66eb6448b8d
golang.org/x/net v0.0.0-20201110031124-69a78807bb2b // indirect
)
Expand Down
7 changes: 4 additions & 3 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,11 @@ github.com/tklauser/numcpus v0.3.0 h1:ILuRUQBtssgnxw0XXIjKUC56fgnOrFoQQ/4+DeU2bi
github.com/tklauser/numcpus v0.3.0/go.mod h1:yFGUr7TUHQRAhyqBcEg0Ge34zDBAsIvJJcyE6boqnA8=
github.com/vcaesar/gops v0.21.2 h1:OwWoJR0zb+AK41TN2adhZUP9lAmaRMzkWwf7Ux5Mx00=
github.com/vcaesar/gops v0.21.2/go.mod h1:BEJGigAc9GORbEegWX9rRon/qwibjDs8p50WYm2KlXw=
github.com/vcaesar/imgo v0.20.0 h1:lX7a2vygTri0Z3VYpwoQA2LPvbphFyT5ON4NTqdC4wQ=
github.com/vcaesar/imgo v0.20.0/go.mod h1:eJscuTEdc6sVn/hZruy8kWi61xqKHLtbAYyPeYcn+t4=
github.com/vcaesar/tt v0.11.0 h1:obQecjgbnAxxC6OYGY6yDvhGRW2PR5wD8Ma2uJH3WGA=
github.com/vcaesar/imgo v0.30.0 h1:ODQVX0EFJEh+WkKahCBtE0SqcDCIjl/kjiOplR0Ouh8=
github.com/vcaesar/imgo v0.30.0/go.mod h1:8TGnt5hjaMgwDByvMFIzUDSh5uSea4n1tAbSvnhvA6U=
github.com/vcaesar/tt v0.11.0/go.mod h1:GHPxQYhn+7OgKakRusH7KJ0M5MhywoeLb8Fcffs/Gtg=
github.com/vcaesar/tt v0.20.0 h1:9t2Ycb9RNHcP0WgQgIaRKJBB+FrRdejuaL6uWIHuoBA=
github.com/vcaesar/tt v0.20.0/go.mod h1:GHPxQYhn+7OgKakRusH7KJ0M5MhywoeLb8Fcffs/Gtg=
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto=
golang.org/x/image v0.0.0-20210628002857-a66eb6448b8d h1:RNPAfi2nHY7C2srAV8A49jpsYr0ADedCk1wq6fTMTvs=
Expand Down
20 changes: 15 additions & 5 deletions img.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,19 @@ func OpenImg(path string) ([]byte, error) {
return imgo.ImgToBytes(path)
}

// Read read the file return image.Image
func Read(path string) (image.Image, error) {
return imgo.Read(path)
}

// Save create a image file with the image.Image
func Save(img image.Image, path string) error {
return imgo.Save(path, img)
}

// SaveImg save the image by []byte
func SaveImg(b []byte, path string) error {
return imgo.Save(path, b)
return imgo.SaveByte(path, b)
}

// SavePng save the image by image.Image
Expand All @@ -43,13 +53,13 @@ func SaveJpeg(img image.Image, path string) error {
}

// ToByteImg convert image.Image to []byte
func ToByteImg(img image.Image) []byte {
return imgo.ToByteImg(img)
func ToByteImg(img image.Image, fm ...string) []byte {
return imgo.ToByteImg(img, fm...)
}

// ToStringImg convert image.Image to string
func ToStringImg(img image.Image) string {
return string(ToByteImg(img))
func ToStringImg(img image.Image, fm ...string) string {
return string(ToByteImg(img, fm...))
}

// StrToImg convert base64 string to image.Image
Expand Down

0 comments on commit 2768d08

Please sign in to comment.