From 168a26ff5dae36df48029911ddee875fee1b3039 Mon Sep 17 00:00:00 2001 From: vcaesar Date: Wed, 26 Jan 2022 09:19:21 -0800 Subject: [PATCH 1/2] add image Save quality support --- go.mod | 2 +- go.sum | 5 ++--- img.go | 8 ++++---- 3 files changed, 7 insertions(+), 8 deletions(-) diff --git a/go.mod b/go.mod index 0d96a29..28c7fb6 100644 --- a/go.mod +++ b/go.mod @@ -9,7 +9,7 @@ require ( github.com/robotn/xgb v0.0.0-20190912153532-2cb92d044934 github.com/robotn/xgbutil v0.0.0-20190912154524-c861d6f87770 github.com/vcaesar/gops v0.22.0 - github.com/vcaesar/imgo v0.30.0 + github.com/vcaesar/imgo v0.30.1 github.com/vcaesar/keycode v0.10.0 github.com/vcaesar/tt v0.20.0 golang.org/x/image v0.0.0-20211028202545-6944b10bf410 // indirect diff --git a/go.sum b/go.sum index 16a189a..b1cda64 100644 --- a/go.sum +++ b/go.sum @@ -35,8 +35,8 @@ 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.22.0 h1:aWHWxY3fvUuaJGph+LegYUSEU/874WJT7MInd8OUmP0= github.com/vcaesar/gops v0.22.0/go.mod h1:GFNGo9xpCfjcfd/Hovi9RSrpd4FdaQt8V92TzpU22w4= -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/imgo v0.30.1 h1:B7QMm2mZY+SGoEvvJwNi+eAv21ptvk2YT1IbP2OzyLE= +github.com/vcaesar/imgo v0.30.1/go.mod h1:n4EluJIN/0UYYGPHBCY/BWlIjdRUdY5U6obtP2lrgdM= github.com/vcaesar/keycode v0.10.0 h1:Qx5QE8ZXHyRyjoA2QOxBp25OKMKB+zxMVqm0FWGV0d4= github.com/vcaesar/keycode v0.10.0/go.mod h1:JNlY7xbKsh+LAGfY2j4M3znVrGEm5W1R8s/Uv6BJcfQ= github.com/vcaesar/tt v0.20.0 h1:9t2Ycb9RNHcP0WgQgIaRKJBB+FrRdejuaL6uWIHuoBA= @@ -45,7 +45,6 @@ github.com/yusufpapurcu/wmi v1.2.2 h1:KBNDSne4vP5mbSWnJbO+51IMOXJB67QiYCSBrubbPR github.com/yusufpapurcu/wmi v1.2.2/go.mod h1:SBZ9tNy3G9/m5Oi98Zks0QjeHVDvuK0qfxQmPyzfmi0= 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/go.mod h1:023OzeP/+EPmXeapQh35lcL3II3LrY8Ic+EFFKVhULM= golang.org/x/image v0.0.0-20211028202545-6944b10bf410 h1:hTftEOvwiOq2+O8k2D5/Q7COC7k5Qcrgc2TFURJYnvQ= golang.org/x/image v0.0.0-20211028202545-6944b10bf410/go.mod h1:023OzeP/+EPmXeapQh35lcL3II3LrY8Ic+EFFKVhULM= golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= diff --git a/img.go b/img.go index 0e2a320..25bbf82 100644 --- a/img.go +++ b/img.go @@ -34,8 +34,8 @@ func Read(path string) (image.Image, error) { } // Save create a image file with the image.Image -func Save(img image.Image, path string) error { - return imgo.Save(path, img) +func Save(img image.Image, path string, quality ...int) error { + return imgo.Save(path, img, quality...) } // SaveImg save the image by []byte @@ -49,8 +49,8 @@ func SavePng(img image.Image, path string) error { } // SaveJpeg save the image by image.Image -func SaveJpeg(img image.Image, path string) error { - return imgo.SaveToJpeg(path, img) +func SaveJpeg(img image.Image, path string, quality ...int) error { + return imgo.SaveToJpeg(path, img, quality...) } // ToByteImg convert image.Image to []byte From 18243a21925a338123bb5118f9fc81137aa55d28 Mon Sep 17 00:00:00 2001 From: vcaesar Date: Wed, 26 Jan 2022 09:26:16 -0800 Subject: [PATCH 2/2] Add multi screen examples code and fixed args --- examples/screen/main.go | 25 ++++++++++++++++++++++++- robotgo.go | 8 ++++---- 2 files changed, 28 insertions(+), 5 deletions(-) diff --git a/examples/screen/main.go b/examples/screen/main.go index 118a8b9..aaa04af 100644 --- a/examples/screen/main.go +++ b/examples/screen/main.go @@ -12,6 +12,7 @@ package main import ( "fmt" + "strconv" "github.com/go-vgo/robotgo" // "go-vgo/robotgo" @@ -26,8 +27,24 @@ func bitmap() { gbitMap := robotgo.CaptureGo() fmt.Println("Go CaptureScreen...", gbitMap.Width) // fmt.Println("...", gbitmap.Width, gbitmap.BytesPerPixel) - // robotgo.SaveCapture("saveCapture.png", 10, 20, 100, 100) + + img := robotgo.CaptureImg() + robotgo.Save(img, "save.png") + + num := robotgo.DisplaysNum() + for i := 0; i < num; i++ { + robotgo.DisplayID = i + img1 := robotgo.CaptureImg() + path1 := "save_" + strconv.Itoa(i) + robotgo.Save(img1, path1+".png") + robotgo.SaveJpeg(img1, path1+".jpeg", 50) + + img2 := robotgo.CaptureImg(10, 10, 20, 20) + path2 := "test_" + strconv.Itoa(i) + robotgo.Save(img2, path2+".png") + robotgo.SaveJpeg(img2, path2+".jpeg", 50) + } } func color() { @@ -64,6 +81,12 @@ func screen() { // gets the screen width and height sx, sy := robotgo.GetScreenSize() fmt.Println("get screen size: ", sx, sy) + for i := 0; i < robotgo.DisplaysNum(); i++ { + s1 := robotgo.ScaleF(i) + fmt.Println("ScaleF: ", s1) + } + sx, sy = robotgo.GetScaleSize() + fmt.Println("get screen sclae size: ", sx, sy) color() } diff --git a/robotgo.go b/robotgo.go index c60374c..9ac4b87 100644 --- a/robotgo.go +++ b/robotgo.go @@ -222,9 +222,9 @@ func GetPixelColor(x, y int, displayId ...int) string { } // GetMouseColor get the mouse pos's color -func GetMouseColor() string { +func GetMouseColor(displayId ...int) string { x, y := GetMousePos() - return GetPixelColor(x, y) + return GetPixelColor(x, y, displayId...) } func displayIdx(id ...int) int { @@ -319,8 +319,8 @@ func CaptureScreen(args ...int) CBitmap { } else { // Get the main screen rect. rect := GetScreenRect(displayId) - x = C.int32_t(rect.X) - y = C.int32_t(rect.Y) + // x = C.int32_t(rect.X) + // y = C.int32_t(rect.Y) w = C.int32_t(rect.W) h = C.int32_t(rect.H) }