From 3f4b0f987251a2a1885a35a17db04bb087231021 Mon Sep 17 00:00:00 2001 From: eric Date: Tue, 18 Jun 2024 20:20:04 +0800 Subject: [PATCH] capture error --- robotgo.go | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/robotgo.go b/robotgo.go index f4660ac..68a2456 100644 --- a/robotgo.go +++ b/robotgo.go @@ -46,6 +46,7 @@ package robotgo import "C" import ( + "errors" "image" "runtime" "time" @@ -360,11 +361,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