capture error (#663)

* capture error

* aohanhongzhi

* Update go.mod

---------

Co-authored-by: Evans <vzvway@gmail.com>
This commit is contained in:
aohanhongzhi 2024-10-08 04:29:39 +08:00 committed by GitHub
parent 217d6cf1f1
commit 8db59aac2d
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -50,6 +50,7 @@ package robotgo
import "C"
import (
"errors"
"image"
"runtime"
"time"
@ -366,11 +367,14 @@ func CaptureGo(args ...int) Bitmap {
}
// CaptureImg capture the screen and return image.Image
func CaptureImg(args ...int) image.Image {
func CaptureImg(args ...int) (image.Image, error) {
bit := CaptureScreen(args...)
if bit == nil {
return nil, errors.New("capture error")
}
defer FreeBitmap(bit)
return ToImage(bit)
return ToImage(bit), nil
}
// FreeBitmap free and dealloc the C bitmap