mirror of
https://github.com/go-vgo/robotgo.git
synced 2025-05-31 06:13:55 +00:00
Merge pull request #446 from go-vgo/bitmap-pr
Add multi screen examples code and fixed args, add image Save quality support
This commit is contained in:
commit
80ee9fcc43
@ -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()
|
||||
}
|
||||
|
2
go.mod
2
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
|
||||
|
5
go.sum
5
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=
|
||||
|
8
img.go
8
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
|
||||
|
@ -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)
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user