1 Star 0 Fork 0

wanne/saya-app

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
TestScreenShot.go 1.10 KB
一键复制 编辑 原始数据 按行查看 历史
wanne 提交于 2023-06-09 17:06 . not nessary
package main
import (
"fmt"
"image"
"image/png"
"os"
"path/filepath"
"github.com/kbinani/screenshot"
)
// This File is only for test
func TestSC() {
num := screenshot.NumActiveDisplays()
if num <= 0 {
panic("Active display not found")
}
var all image.Rectangle = image.Rect(0, 0, 0, 0)
for i := 0; i < num; i++ {
//device, _ := screenshot.CaptureDisplay(i)
bounds := screenshot.GetDisplayBounds(i)
all = all.Union(bounds)
img, err := screenshot.CaptureRect(bounds)
if err != nil {
panic(err)
}
fileName := fmt.Sprintf("test/%d_%dx%d.png", i, bounds.Dx(), bounds.Dy())
save(img, fileName)
fmt.Printf("#%d : %v \"%s\"\n", i, bounds, fileName)
}
// Capture all desktop region into an image.
fmt.Printf("%v\n", all)
img, err := screenshot.Capture(all.Min.X, all.Min.Y, all.Dx(), all.Dy())
if err != nil {
panic(err)
}
save(img, "test/all.png")
}
func save(img *image.RGBA, fileName string) {
parent := filepath.Dir(fileName)
if parent != "" {
os.MkdirAll(parent, 0666)
}
f, err := os.Create(fileName)
if err != nil {
panic(err)
}
defer f.Close()
png.Encode(f, img)
}
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/wanneme/saya-app.git
git@gitee.com:wanneme/saya-app.git
wanneme
saya-app
saya-app
main

搜索帮助

D67c1975 1850385 1daf7b77 1850385