screenshot

package module
v0.0.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 21, 2026 License: MIT Imports: 15 Imported by: 0

README

screenshot

Project Badges

=========

Go library to capture desktop screen. Fork of kbinani/screenshot.

  • Multiple display supported.
  • Supported GOOS: windows, darwin, linux, freebsd, openbsd, netbsd.
  • cgo free except for GOOS=darwin.

Install

go get github.com/tinywasm/screenshot

Example

package main

import (
	"fmt"
	"image/png"
	"os"

	"github.com/tinywasm/screenshot"
)

func main() {
	n := screenshot.NumActiveDisplays()

	for i := 0; i < n; i++ {
		bounds := screenshot.GetDisplayBounds(i)

		img, err := screenshot.CaptureRect(bounds)
		if err != nil {
			panic(err)
		}
		fileName := fmt.Sprintf("%d_%dx%d.png", i, bounds.Dx(), bounds.Dy())
		file, _ := os.Create(fileName)
		defer file.Close()
		png.Encode(file, img)

		fmt.Printf("#%d : %v \"%s\"\n", i, bounds, fileName)
	}
}

Output example:

$ go run main.go
#0 : (0,0)-(1280,800) "0_1280x800.png"
#1 : (-293,-1440)-(2267,0) "1_2560x1440.png"
#2 : (-1373,-1812)-(-293,108) "2_1080x1920.png"

Coordinate System

Y-axis is downward. The origin is the upper-left corner of the main display (same as Windows coordinate system).

License

MIT — original author: kbinani

Documentation

Overview

Package screenshot captures screen-shot image as image.RGBA. Mac, Windows, Linux, FreeBSD, OpenBSD and NetBSD are supported.

Index

Constants

This section is empty.

Variables

View Source
var ErrUnsupported = errors.New("screenshot does not support your platform")

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

Functions

func Capture

func Capture(x, y, width, height int) (img *image.RGBA, e error)

Capture returns screen capture of specified desktop region. x and y represent distance from the upper-left corner of primary display. Y-axis is downward direction. This means coordinates system is similar to Windows OS.

func CaptureDisplay

func CaptureDisplay(displayIndex int) (*image.RGBA, error)

CaptureDisplay captures whole region of displayIndex'th display, starts at 0 for primary display.

func CaptureRect

func CaptureRect(rect image.Rectangle) (*image.RGBA, error)

CaptureRect captures specified region of desktop.

func GetDisplayBounds

func GetDisplayBounds(displayIndex int) (rect image.Rectangle)

GetDisplayBounds returns the bounds of displayIndex'th display. The main display is displayIndex = 0.

func NumActiveDisplays

func NumActiveDisplays() (num int)

NumActiveDisplays returns the number of active displays.

Types

This section is empty.

Directories

Path Synopsis
internal
dbus
Package dbus implements bindings to the D-Bus message bus system.
Package dbus implements bindings to the D-Bus message bus system.
shm
Package shm implements System V shared memory functions (shmctl, shmget, shmat, shmdt).
Package shm implements System V shared memory functions (shmctl, shmget, shmat, shmdt).
sys/windows
Package windows contains an interface to the low-level operating system primitives.
Package windows contains an interface to the low-level operating system primitives.
win
xgb
Package XGB provides the X Go Binding, which is a low-level API to communicate with the core X protocol and many of the X extensions.
Package XGB provides the X Go Binding, which is a low-level API to communicate with the core X protocol and many of the X extensions.
xgb/shm
Package shm is the X client API for the MIT-SHM extension.
Package shm is the X client API for the MIT-SHM extension.
xgb/xinerama
Package xinerama is the X client API for the XINERAMA extension.
Package xinerama is the X client API for the XINERAMA extension.
xgb/xproto
Package xproto is the X client API for the extension.
Package xproto is the X client API for the extension.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL