screenshot

kbinaniMIT长期未更新

Go 语言写的桌面截屏库,能把当前屏幕画面直接抓成图像对象,方便在 Go 程序里集成截图功能。

Go library to capture desktop to image

暂无版本1,566star213fork同步于 2026-11-07 07:33 UTC

怎么上手

由 README 提炼,执行前请确认
go get github.com/kbinani/screenshot
硬件要求按 README 说明

README 未说明硬件要求,也未提及显存或 GPU 型号;仅说明支持的操作系统为 windows、darwin、linux、freebsd、openbsd、netbsd。

下载:源码 zip·GitHub Releases(安装包)本站不镜像安装包

项目说明

由 README 自动翻译提炼

Go 写的桌面截屏库,把多显示器画面直接抓成 image.Image,方便在 Go 程序里做截图

Go 语言写的桌面截屏库,能把当前屏幕画面直接抓成图像对象,方便在 Go 程序里集成截图功能。

核心能力

  • 用 NumActiveDisplays 和 GetDisplayBounds 枚举多显示器
  • 用 CaptureRect 按矩形区域截取屏幕图像
  • 支持 windows、darwin、linux 及三种 BSD 系统
  • 除 darwin 外均无需 cgo,纯 Go 编译即可

容易踩的坑

darwin 平台依赖 cgo,交叉编译或纯 Go 构建会失败;坐标系 Y 轴向下、原点在主显示器左上角,与部分 GUI 框架相反,拼接多屏坐标时容易算错;README 未说明 Linux 下是否需要 X11 等图形环境依赖。

内容由模型根据 README 生成,可能不完整或不准确,以官方文档为准。看原文 README

最近发版

0 个版本

暂无 release 数据(可能没有发版,或尚未同步)。

用户点评

登录用户的真实使用记录,可按版本和硬件筛选
共 0 条

    还没有人点评。第一个说出真实体验的人最有价值。

    README 原文

    未翻译

    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
      

    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