-
Notifications
You must be signed in to change notification settings - Fork 178
/
screenshot.go
39 lines (32 loc) · 1.11 KB
/
screenshot.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
// Package screenshot captures screen-shot image as image.RGBA.
// Mac, Windows, Linux, FreeBSD, OpenBSD and NetBSD are supported.
package screenshot
import (
"errors"
"image"
)
// ErrUnsupported is returned when the platform or architecture used to compile the program
// does not support screenshot, e.g. if you're compiling without CGO on Darwin
var ErrUnsupported = errors.New("screenshot does not support your platform")
// CaptureDisplay captures whole region of displayIndex'th display, starts at 0 for primary display.
func CaptureDisplay(displayIndex int) (*image.RGBA, error) {
rect := GetDisplayBounds(displayIndex)
return CaptureRect(rect)
}
// CaptureRect captures specified region of desktop.
func CaptureRect(rect image.Rectangle) (*image.RGBA, error) {
return Capture(rect.Min.X, rect.Min.Y, rect.Dx(), rect.Dy())
}
func createImage(rect image.Rectangle) (img *image.RGBA, e error) {
img = nil
e = errors.New("Cannot create image.RGBA")
defer func() {
err := recover()
if err == nil {
e = nil
}
}()
// image.NewRGBA may panic if rect is too large.
img = image.NewRGBA(rect)
return img, e
}