Documentation
¶
Overview ¶
Package camera shows what a phone's camera sees in a window's native UI, and takes photos and reads the QR codes it sees: AVCaptureSession on iOS, CameraX on Android (with ZXing for the codes). For a photo in the system's own camera screen, use package imagepicker: it needs no permission.
cam, err := camera.New(win, camera.Options{})
...
ui.WebView(c, cam).Fill() // in the view; what it draws after shows over the preview
path, err := cam.TakePhoto(ctx)
To scan a QR code, as an app imports a link or a key shown on another screen:
cam, err := camera.New(win, camera.Options{OnCode: func(code camera.Code) {
link = code.Text
win.Update(func() {})
}})
The preview shows under the content, as a web view does. On desktops and in browsers New reports errors.ErrUnsupported.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Camera ¶
type Camera struct {
// contains filtered or unexported fields
}
Camera is a preview of a camera, which takes photos. Show it with ui.WebView.
func New ¶
New asks the user for the camera, the first time, and makes its preview in a window showing native UI.
func (*Camera) Destroy ¶
func (c *Camera) Destroy()
Destroy stops the camera and takes its preview away.
func (*Camera) SurfaceWebView ¶
SurfaceWebView gives package ui the view to show.
type Code ¶ added in v0.11.0
type Code struct {
// Text is what the code holds.
Text string
}
Code is a QR code the camera saw.
type Options ¶
type Options struct {
// Front chooses the camera on the screen's side.
Front bool
// OnCode, when set, is called on the main thread with each QR code that
// comes into the camera's view: once while it stays in view, as several
// codes in view are told once each. A code read again after it was out of
// view for a second is told again.
OnCode func(Code)
}
Options are which camera shows, and what it reads.