Skip to content

Commit

Permalink
Update: update screen capture code and examples
Browse files Browse the repository at this point in the history
  • Loading branch information
vcaesar committed Oct 7, 2024
1 parent 8db59aa commit 47cde13
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 8 deletions.
2 changes: 1 addition & 1 deletion .circleci/images/primary/Dockerfile
Original file line number Diff line number Diff line change
@@ -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 \
Expand Down
4 changes: 2 additions & 2 deletions robotgo.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
9 changes: 4 additions & 5 deletions screen.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
package robotgo

import (
"errors"
"image"

"github.com/kbinani/screenshot"
Expand All @@ -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 {
Expand All @@ -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)
Expand Down

0 comments on commit 47cde13

Please sign in to comment.