mirror of
https://github.com/go-vgo/robotgo.git
synced 2025-05-29 21:43:55 +00:00
Update: update screen capture code and examples
This commit is contained in:
parent
8db59aac2d
commit
47cde13dab
@ -1,5 +1,5 @@
|
||||
# FROM golang:1.10.1
|
||||
FROM golang:1.22.3-stretch AS build
|
||||
FROM golang:1.23.2-stretch AS build
|
||||
# FROM govgo/go:1.11.1
|
||||
|
||||
RUN apt update && apt install -y --no-install-recommends \
|
||||
|
@ -366,11 +366,11 @@ func CaptureGo(args ...int) Bitmap {
|
||||
return ToBitmap(bit)
|
||||
}
|
||||
|
||||
// CaptureImg capture the screen and return image.Image
|
||||
// CaptureImg capture the screen and return image.Image, error
|
||||
func CaptureImg(args ...int) (image.Image, error) {
|
||||
bit := CaptureScreen(args...)
|
||||
if bit == nil {
|
||||
return nil, errors.New("capture error")
|
||||
return nil, errors.New("Capture image not found.")
|
||||
}
|
||||
defer FreeBitmap(bit)
|
||||
|
||||
|
@ -11,7 +11,6 @@
|
||||
package robotgo
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"image"
|
||||
|
||||
"github.com/kbinani/screenshot"
|
||||
@ -31,7 +30,7 @@ func GetDisplayRect(i int) Rect {
|
||||
Size{W: w, H: h}}
|
||||
}
|
||||
|
||||
// Capture capture the screenshot
|
||||
// Capture capture the screenshot, use the CaptureImg default
|
||||
func Capture(args ...int) (*image.RGBA, error) {
|
||||
displayId := 0
|
||||
if DisplayID != -1 {
|
||||
@ -54,9 +53,9 @@ func Capture(args ...int) (*image.RGBA, error) {
|
||||
|
||||
// SaveCapture capture screen and save the screenshot to image
|
||||
func SaveCapture(path string, args ...int) error {
|
||||
img := CaptureImg(args...)
|
||||
if img == nil {
|
||||
return errors.New("Capture image not found")
|
||||
img, err := CaptureImg(args...)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return Save(img, path)
|
||||
|
Loading…
Reference in New Issue
Block a user