-
Notifications
You must be signed in to change notification settings - Fork 8
/
qrcode.go
42 lines (33 loc) · 979 Bytes
/
qrcode.go
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
package mobile
import (
"image/draw"
"github.com/brunoga/robomaster/sdk2/module/camera"
"github.com/brunoga/robomaster/sdk2/unitybridge/support/qrcode"
)
// QRCode allows generating QRCodes that can be read by a Robomaster robot.
type QRCode struct {
q *qrcode.QRCode
}
// NewQRCode creates a new QRCode instance. The bssID parameter is optional
// and may be an empty string.
func NewQRCode(appID int64, countryCode, ssID, password,
bssID string) (*QRCode, error) {
q, err := qrcode.New(uint64(appID), countryCode, ssID, password, bssID)
if err != nil {
return nil, err
}
return &QRCode{
q: q,
}, nil
}
// Image returns the QRCode image (with size as its width and height) as a byte
// slice with RGB24 image data.
func (q *QRCode) Image(size int) ([]byte, error) {
img, err := q.q.Image(size)
if err != nil {
return nil, err
}
rgb := camera.NewRGB(img.Bounds())
draw.Draw(rgb, img.Bounds(), img, img.Bounds().Min, draw.Src)
return rgb.Pix, nil
}