-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcapture_test.go
More file actions
49 lines (45 loc) · 830 Bytes
/
capture_test.go
File metadata and controls
49 lines (45 loc) · 830 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
package gdesk
import (
"image"
"image/png"
"os"
"testing"
"time"
)
func TestCapture(t *testing.T) {
display := GetPrimaryDisplay()
var c = NewCapturer()
c.Start(display)
defer c.Stop()
var f *Frame
for {
f = c.GetFrame()
if f != nil {
break
}
time.Sleep(10 * time.Millisecond)
}
defer f.Release()
w := int(display.Width())
h := int(display.Height())
rect := image.Rect(0, 0, w, h)
img := image.NewRGBA(rect)
rgb := i420ToRgb(w, h, f.data)
file, _ := os.Create("image.png")
dst := make([]byte, w*h*4)
stride := len(rgb) / h
idx := 0
for y := 0; y < h; y++ {
for x := 0; x < w; x++ {
i := stride*y + 3*x
dst[idx] = rgb[i]
dst[idx+1] = rgb[i+1]
dst[idx+2] = rgb[i+2]
dst[idx+3] = 255
idx += 4
}
}
img.Pix = dst
png.Encode(file, img)
time.Sleep(20 * time.Millisecond)
}