go-tg-screenshot-bot
39 строк · 1.1 Кб
1// Package screenshot captures screen-shot image as image.RGBA.
2// Mac, Windows, Linux, FreeBSD, OpenBSD and NetBSD are supported.
3package screenshot4
5import (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
12var 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.
15func CaptureDisplay(displayIndex int) (*image.RGBA, error) {16rect := GetDisplayBounds(displayIndex)17return CaptureRect(rect)18}
19
20// CaptureRect captures specified region of desktop.
21func CaptureRect(rect image.Rectangle) (*image.RGBA, error) {22return Capture(rect.Min.X, rect.Min.Y, rect.Dx(), rect.Dy())23}
24
25func createImage(rect image.Rectangle) (img *image.RGBA, e error) {26img = nil27e = errors.New("Cannot create image.RGBA")28
29defer func() {30err := recover()31if err == nil {32e = nil33}34}()35// image.NewRGBA may panic if rect is too large.36img = image.NewRGBA(rect)37
38return img, e39}
40