Camera capture (Pro)
ProIncluded in $99Point the camera at something and ask about it: the subject is outlined, the shot freezes into a crop, and the question goes with the picture.
On this page
Installation
Needs chatcn Pro
This command works with a Pro license, along with every Pro component.
Or start free: sign up and get three Pro components on us, with a new one every month.
Usage
import { CameraCapture } from "@/components/ui/chatcn/pro/camera-capture"
<CameraCapture
stream={cameraStream} // from getUserMedia; or still={{ src, alt }} for demos
subject={{ x: 0.1, y: 0.25, w: 0.78, h: 0.49 }} // from your detector, in fractions of the frame
suggestions={["How do I replace the ribbon on this?", "What model is this?"]}
onAsk={({ image, prompt }) => sendToChat(image, prompt)}
onClose={closeCamera}
/>Laid out like the phone's own camera: black bands with close and flash above, the viewfinder in the middle, the shutter below. When you pass a subject (from your own detector), it is outlined in the viewfinder. The shutter flashes and freezes exactly what the viewfinder showed; a crop box starts on the subject, or in the middle, with the rest dimmed. Drag the box or its corners, or focus it and use the arrow keys (Shift resizes). A suggested question sends at once, or type one. onAsk gets the cropped picture as a JPEG data URL at the camera's full resolution, the crop and the prompt. Retake goes back to the live view. With no stream, still stands in for the camera.
Examples
States
Props
| Prop | Type | Notes |
|---|---|---|
stream | MediaStream | null | A live camera |
still | { src, alt } | A photo standing in for the camera |
subject | { x, y, w, h } | In fractions of the frame; outlined and the crop starts there |
suggestions | string[] | Question chips after the shot |
onAsk | (result) => void | { image, crop, prompt } |
onClose | () => void | The close button |
labels | Partial<CameraCaptureLabels> | Every string, for translation |
Keyboard
| Key | Action |
|---|---|
| Arrow keys on the crop | Move it |
| Shift with arrow keys | Resize it |
| Enter in the field | Ask |
Accessibility
- Every control is a named button; flash reports whether it is on.
- The crop is a focusable slider that says its size, with keyboard moves and resizing.
- The outlined subject is announced as Subject found.
Motion
A white flash fades over 380 ms on the shutter. Under reduced motion there is no flash.