camera

package
v0.11.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 1, 2026 License: MIT Imports: 5 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

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

func New(w *mygo.Window, o Options) (*Camera, error)

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

func (c *Camera) SurfaceWebView(conn *surface.Conn) platform.WebView

SurfaceWebView gives package ui the view to show.

func (*Camera) TakePhoto

func (c *Camera) TakePhoto(ctx context.Context) (string, error)

TakePhoto takes a photo and returns the path of its JPEG in the app's temporary directory.

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.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL