CameraRef

interface CameraRef extends PreviewViewMethods, Pick

A React-ref to the Camera view.

Example

function App() {
  const camera = useRef<CameraRef>(null)
  return <Camera {...props} ref={camera} />
}

Properties

controller

controller: 
  | CameraController
  | undefined

Get the current CameraController. This property will be set after onStarted has been called, and may change over time.


preview

preview: PreviewView | undefined

Get a ref to the PreviewView, or undefined if it has not yet been set. This value is set after the first mount, and usually won't change.

Methods

cancelZoomAnimation()

cancelZoomAnimation(): Promise<void>

Cancels any zoom animations previously started with startZoomAnimation(...).

Inherited from

CameraController.cancelZoomAnimation


convertCameraPointToViewPoint()

convertCameraPointToViewPoint(cameraPoint: Point): Point

Converts the given cameraPoint in camera sensor coordinates into a Point in view coordinates, relative to this PreviewView.

Note

Camera sensor coordinates are not necessarily normalized from 0.0 to 1.0. Some implementations may have a different opaque coordinate system.

Throws

If the PreviewView isn't ready yet.

Example

const cameraPoint = { x: 0.5, y: 0.5 }
const viewPoint = previewView.convertCameraPointToViewPoint(cameraPoint)
console.log(viewPoint) // { x: 196, y: 379.5 }

Inherited from

PreviewViewMethods.convertCameraPointToViewPoint


convertScannedObjectCoordinatesToViewCoordinates()

iOS
convertScannedObjectCoordinatesToViewCoordinates(scannedObject: ScannedObject): ScannedObject

Returns a new ScannedObject where all coordinates in the given scannedObject are converted into view coordinates.

Parameters

scannedObject

The scanned object in its original coordinates.

Inherited from

PreviewViewMethods.convertScannedObjectCoordinatesToViewCoordinates


convertViewPointToCameraPoint()

convertViewPointToCameraPoint(viewPoint: Point): Point

Converts the given viewPoint in view coordinates relative to this PreviewView into a Point in camera sensor coordinates.

Note

Camera sensor coordinates are not necessarily normalized from 0.0 to 1.0. Some implementations may have a different opaque coordinate system.

Throws

If the PreviewView isn't ready yet.

Example

const viewPoint = { x: 196, y: 379.5 }
const cameraPoint = previewView.convertViewPointToCameraPoint(viewPoint)
console.log(cameraPoint) // { x: 0.5, y: 0.5 }

Inherited from

PreviewViewMethods.convertViewPointToCameraPoint


createMeteringPoint()

createMeteringPoint(
   viewX: number, 
   viewY: number, 
   size?: number): MeteringPoint

Creates a MeteringPoint that can be used for focusing AE/AF/AWB on the Camera via focusTo(...).

The coordinates (viewX, viewY) are relative to this PreviewView, and take orientation, scaling and cropping into account.

Parameters

viewX

The X coordinate within the View's coordinate system. This can be the x value of a tap event on the PreviewView.

viewY

The Y coordinate within the View's coordinate system. This can be the y value of a tap event on the PreviewView.

size

(Optional) The size of the MeteringPoint within the View's coordinate system.

Throws

If the PreviewView isn't ready yet.

Inherited from

PreviewViewMethods.createMeteringPoint


focusTo()

focusTo(viewPoint: Point, options?: FocusOptions): Promise<void>

Focuses the Camera pipeline to the specified viewPoint relative to the Camera view's coordinate system using the specified MeteringModes.

Parameters

viewPoint

The point in the view coordinate system to focus to.

options

Options for the focus operation.

Throws

If the Camera isn't ready yet.

Example

// Focus center
await camera.current.focusTo({ x: width / 2, y: height / 2 })

resetFocus()

resetFocus(): Promise<void>

Cancels any current focus operations from focusTo(...), resets back all 3A focus modes to continuously auto-focus, and resets the focus point of interest to be in the center.

Throws

If the device does not support metering (see CameraDevice.supportsFocusMetering)

Example

await controller.resetFocus()

Inherited from

CameraController.resetFocus


startZoomAnimation()

startZoomAnimation(zoom: number, rate: number): Promise<void>

Starts animating the Camera's zoom to the specified zoom value, at the specified rate.

Throws

If the CameraDevice does not support the given zoom value. See CameraDevice.minZoom / CameraDevice.maxZoom

Example

Zoom to the maximum:

const controller = ...
const maxZoom = controller.device.maxZoom
await controller.startZoomAnimation(maxZoom, 2)

Inherited from

CameraController.startZoomAnimation


takeSnapshot()

Android
takeSnapshot(): Promise<Image>

Take a snapshot of the current PreviewView's contents, and return it as an Image.

Throws

If the PreviewView isn't ready yet.

Throws

If the PreviewView doesn't have snapshottable contents.

Throws

If the PreviewView doesn't support snapshots.

Inherited from

PreviewViewMethods.takeSnapshot