go-tg-screenshot-bot

Форк
0
39 строк · 1.1 Кб
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
}
40

Использование cookies

Мы используем файлы cookie в соответствии с Политикой конфиденциальности и Политикой использования cookies.

Нажимая кнопку «Принимаю», Вы даете АО «СберТех» согласие на обработку Ваших персональных данных в целях совершенствования нашего веб-сайта и Сервиса GitVerse, а также повышения удобства их использования.

Запретить использование cookies Вы можете самостоятельно в настройках Вашего браузера.