diff --git a/README.md b/README.md index 9c3b4c8a..72977c45 100644 --- a/README.md +++ b/README.md @@ -15,7 +15,7 @@ - >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. diff --git a/README_zh.md b/README_zh.md index b2a84710..38163dd8 100644 --- a/README_zh.md +++ b/README_zh.md @@ -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). diff --git a/examples/bitmap/main.go b/examples/bitmap/main.go index be1dee62..9c3662db 100644 --- a/examples/bitmap/main.go +++ b/examples/bitmap/main.go @@ -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) @@ -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) diff --git a/go.mod b/go.mod index 7cf0e864..c4147aa2 100644 --- a/go.mod +++ b/go.mod @@ -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 ) diff --git a/go.sum b/go.sum index 402ddcaa..2a4a91ec 100644 --- a/go.sum +++ b/go.sum @@ -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= diff --git a/img.go b/img.go index f40da775..69d2d302 100644 --- a/img.go +++ b/img.go @@ -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 @@ -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