| 1 |
screenshot |
| 2 |
========== |
| 3 |
|
| 4 |
 |
| 5 |
[](https://godoc.org/github.com/kbinani/screenshot) |
| 6 |
[](https://github.com/kbinani/screenshot/blob/master/LICENSE) |
| 7 |
[](https://goreportcard.com/report/github.com/kbinani/screenshot) |
| 8 |
|
| 9 |
* Go library to capture desktop screen. |
| 10 |
* Multiple display supported. |
| 11 |
* Supported GOOS: windows, darwin, linux, freebsd, openbsd, and netbsd. |
| 12 |
* `cgo` free except for GOOS=darwin. |
| 13 |
|
| 14 |
example |
| 15 |
======= |
| 16 |
|
| 17 |
* sample program `main.go` |
| 18 |
|
| 19 |
```go |
| 20 |
package main |
| 21 |
|
| 22 |
import ( |
| 23 |
"github.com/kbinani/screenshot" |
| 24 |
"image/png" |
| 25 |
"os" |
| 26 |
"fmt" |
| 27 |
) |
| 28 |
|
| 29 |
func main() { |
| 30 |
n := screenshot.NumActiveDisplays() |
| 31 |
|
| 32 |
for i := 0; i < n; i++ { |
| 33 |
bounds := screenshot.GetDisplayBounds(i) |
| 34 |
|
| 35 |
img, err := screenshot.CaptureRect(bounds) |
| 36 |
if err != nil { |
| 37 |
panic(err) |
| 38 |
} |
| 39 |
fileName := fmt.Sprintf("%d_%dx%d.png", i, bounds.Dx(), bounds.Dy()) |
| 40 |
file, _ := os.Create(fileName) |
| 41 |
defer file.Close() |
| 42 |
png.Encode(file, img) |
| 43 |
|
| 44 |
fmt.Printf("#%d : %v \"%s\"\n", i, bounds, fileName) |
| 45 |
} |
| 46 |
} |
| 47 |
``` |
| 48 |
|
| 49 |
* output example |
| 50 |
|
| 51 |
```bash |
| 52 |
$ go run main.go |
| 53 |
#0 : (0,0)-(1280,800) "0_1280x800.png" |
| 54 |
#1 : (-293,-1440)-(2267,0) "1_2560x1440.png" |
| 55 |
#2 : (-1373,-1812)-(-293,108) "2_1080x1920.png" |
| 56 |
$ ls -1 |
| 57 |
0_1280x800.png |
| 58 |
1_2560x1440.png |
| 59 |
2_1080x1920.png |
| 60 |
main.go |
| 61 |
``` |
| 62 |
|
| 63 |
coordinate |
| 64 |
================= |
| 65 |
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 |
| 66 |
|
| 67 |
license |
| 68 |
======= |
| 69 |
|
| 70 |
MIT Licence |
| 71 |
|
| 72 |
author |
| 73 |
====== |
| 74 |
|
| 75 |
kbinani |