Debian Codegraph @

screenshot.go

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