From 8db59aac2d88c7e6263d67a7917d13e736955888 Mon Sep 17 00:00:00 2001 From: aohanhongzhi <37319319+aohanhongzhi@users.noreply.github.com> Date: Tue, 8 Oct 2024 04:29:39 +0800 Subject: [PATCH] capture error (#663) * capture error * aohanhongzhi * Update go.mod --------- Co-authored-by: Evans --- robotgo.go | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/robotgo.go b/robotgo.go index 4057b28..b7b6888 100644 --- a/robotgo.go +++ b/robotgo.go @@ -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