Skip to content
Go library to capture desktop to image
Branch: master
Clone or download
kbinani Merge pull request #13 from discoverkl/master
fix panic while no display is active
Latest commit c3c7d93 Jun 12, 2019
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
.travis Use MIT-SHM shared memory Mar 12, 2018
example Infra: enable travis (#1) Sep 29, 2016
internal Don't swallow xinerama Init errors Feb 15, 2019
.travis.yml Fix build failure when go version 1.10.4 and later Dec 8, 2018
LICENSE Documentation Sep 27, 2016
README.md Support Solaris Oct 2, 2016
screenshot.go Support Solaris Oct 2, 2016
screenshot_darwin.go
screenshot_freebsd.go Support OpenBSD and NetBSD Oct 1, 2016
screenshot_go1.9_or_earlier_darwin.go Fix build failure on Linux Feb 19, 2018
screenshot_linux.go gofmt -s -w -l . Sep 29, 2016
screenshot_netbsd.go Support OpenBSD and NetBSD Oct 1, 2016
screenshot_openbsd.go Support OpenBSD and NetBSD Oct 1, 2016
screenshot_solaris.go Support Solaris Oct 2, 2016
screenshot_windows.go Fix failing GetDIBits on Windows Aug 23, 2018

README.md

screenshot

Build Status Go Report Card

  • Go library to capture desktop screen.
  • Support Windows, Mac, Linux, FreeBSD, OpenBSD, NetBSD, and Solaris environment.
  • Multiple display supported.
  • cgo free for Windows, Linux, FreeBSD, OpenBSD, NetBSD, and Solaris.

example

  • sample program main.go

     package main
    
     import (
     	"github.com/kbinani/screenshot"
     	"image/png"
     	"os"
     	"fmt"
     )
    
     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"
     $ ls -1
     0_1280x800.png
     1_2560x1440.png
     2_1080x1920.png
     main.go

coordinate

Y-axis is downward direction in this library. The origin of coordinate is upper-left corner of main display. This means coordinate system is similar to Windows OS

license

MIT Licence

author

kbinani

You can’t perform that action at this time.