Skip to content

Go library to capture desktop to image

License

Notifications You must be signed in to change notification settings

chuckn408/screenshot

This branch is 2 commits ahead of, 4 commits behind kbinani/screenshot:master.

Folders and files

NameName
Last commit message
Last commit date

Latest commit

8a83d0a · Jan 6, 2025
Aug 9, 2024
Jul 31, 2023
Sep 27, 2016
Jan 6, 2025
Aug 20, 2024
Aug 20, 2024
Aug 20, 2024
Aug 20, 2024
Aug 20, 2024
Aug 20, 2024
Aug 20, 2024
Aug 20, 2024
Aug 20, 2024
Mar 22, 2021
Aug 20, 2024
Aug 20, 2024

Repository files navigation

Screenshot

Go Report Card

  • Go library to capture desktop screen.
  • Multiple display supported.
  • Supported GOOS: windows, darwin, linux, freebsd, openbsd, and netbsd.
  • cgo free except for GOOS=darwin.

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

List of Functions

NumActiveDisplays()

GetDisplayBounds()

getDesktopWindow()

enumDisplayMonitors()

countupMonitorCallback()

getMonitorBoundsCallback()

getMonitorRealSize()
  • screenshot.go
CaptureDisplay()

CaptureRect()

createImage()

Coordinate System

The coordinate system is similar to Windows OS in that the he origin of Y-axis coordinate is upper-left corner of main display, in a downward direction.

License

MIT Licence

Author

kbinani

About

Go library to capture desktop to image

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Go 100.0%