Skip to main content
Version: 0.2.0

Class: Camera

CameraView.Camera

A camera component with CameraProps.onCapture and CameraProps.onFrame callbacks. To programmatically trigger a capture, call the takePicture function.

export default function App() {
const {imageClass, processImage} = useImageClassification(
require('./resnet18.ptl'),
);

const handleFrame = useCallback(
async (image: Image) => {
await processImage(image);
image.release();
},
[processImage],
);

return (
<>
<Camera
style={styles.camera}
onFrame={handleFrame}
hideCaptureButton={true}
/>
<Text>{imageClass}</Text>
</>
);
}

component

Hierarchy

Methods

flip

flip(): void

Returns

void

Defined in

CameraView.tsx:212


takePicture

takePicture(): void

The takePicture function captures an image from the camera and then trigger the onCapture callback registered on the Camera component.

export default function CameraTakePicture() {
const cameraRef = React.useRef<Camera>(null);

async function handleCapture(image: Image) {
// Use captured image before releasing it.
image.release();
}

function handleTakePicture() {
const camera = cameraRef.current;
if (camera != null) {
camera.takePicture();
}
}

return (
<>
<Camera
ref={cameraRef}
onCapture={handleCapture}
hideCaptureButton={true}
style={StyleSheet.absoluteFill}
targetResolution={{width: 480, height: 640}}
facing={CameraFacing.BACK}
/>
<Button title="Take Picture" onPress={handleTakePicture} />
</>
);
}

Returns

void

Defined in

CameraView.tsx:198