screenshot
=========
Go library to capture desktop screen. Fork of kbinani/screenshot.
- Multiple display supported.
- Supported GOOS:
windows,darwin,linux,freebsd,openbsd,netbsd. cgofree except forGOOS=darwin.
go get github.com/tinywasm/screenshotpackage 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"Y-axis is downward. The origin is the upper-left corner of the main display (same as Windows coordinate system).
MIT — original author: kbinani