시작하기
설치
Set up this Capacitor plugin in the project.
Use the package manager already used by the project.
Install these package(s): `@capgo/camera-preview`
Run the required Capacitor sync/update step after installation.
Read this markdown guide for the full setup steps: https://raw.githubusercontent.com/Cap-go/website/refs/heads/main/apps/docs/src/content/docs/docs/plugins/camera-preview/getting-started.mdx
Use that guide for platform-specific steps, native file edits, permissions, config changes, imports, and usage setup.
If that guide references other docs pages, read them too.
설치
설치Capgo AI-Assisted Setup을 사용하여 플러그인을 설치할 수 있습니다. AI 도구에 Capgo 기능을 추가하려면 다음 명령어를 사용하세요:
npx skills add https://github.com/Cap-go/capgo-skills --skill capacitor-plugins페이지/영역: Capgo 마케팅 웹사이트. 역할: UI 레이블. 표시되는 곳: page agents/[slug].astro. 메시지 키 `agents_page_copy_label` (Agents Page Copy Label).
Use the `capacitor-plugins` skill from `Cap-go/capgo-skills` to install the `@capgo/camera-preview` plugin in my project.그런 다음 다음 프롬프트를 사용하세요:
bun add @capgo/camera-previewbunx cap syncImport
Importimport { CameraPreview } from '@capgo/camera-preview';API 개요
API 개요start
시작카메라 프리뷰를 시작합니다.
import { CameraPreview } from '@capgo/camera-preview';
const result = await CameraPreview.start({ parent: 'parent' });console.log(result);stop
중지카메라 프리뷰를 중지합니다.
import { CameraPreview } from '@capgo/camera-preview';
await CameraPreview.stop();capture
촬영카메라에서 사진을 캡처합니다.
만약 storeToFile 시작할 때 true 캡처 프리뷰를 설정한 경우, 반환된
value 은 기기에서 절대 파일 경로가 아닌 base64 문자열이 아닌 절대 파일 경로가 될 것입니다. getBase64FromFilePath 함수를 사용하여 파일 경로에서 base64 문자열을 얻으세요.
import { CameraPreview } from '@capgo/camera-preview';
const result = await CameraPreview.capture({ height: 1920 });console.log(result);captureSample
캡처 샘플캠코더 프리뷰 스트림에서 단일 프레임을 캡처합니다.
import { CameraPreview } from '@capgo/camera-preview';
const result = await CameraPreview.captureSample({ quality: 85, mirrorFrontCamera: false,});console.log(result);getSupportedFlashModes
지원하는 플래시 모드활성 카메라에서 지원하는 플래시 모드를 가져옵니다.
import { CameraPreview } from '@capgo/camera-preview';
const result = await CameraPreview.getSupportedFlashModes();console.log(result);setAspectRatio
비율 설정카메라 프리뷰의 비율을 설정하세요.
import { CameraPreview } from '@capgo/camera-preview';
await CameraPreview.setAspectRatio({} as { aspectRatio: '4:3' | '16:9'; x?: number; y?: number });getAspectRatio
비율을 가져오기카메라 프리뷰의 현재 비율을 가져옵니다.
import { CameraPreview } from '@capgo/camera-preview';
const result = await CameraPreview.getAspectRatio();console.log(result);setGridMode
그리드 모드를 설정하세요.카메라 프리뷰 오버레이의 현재 그리드 모드를 가져옵니다.
import { CameraPreview } from '@capgo/camera-preview';
await CameraPreview.setGridMode({ gridMode: 'none' });getGridMode
권한을 확인하세요.getAspectRatio
import { CameraPreview } from '@capgo/camera-preview';
const result = await CameraPreview.getGridMode();console.log(result);checkPermissions
checkPermissions현재 카메라 (및 선택적으로 마이크)의 권한 상태를 확인합니다. 시스템 대화창을 표시하지 않고.
import { CameraPreview } from '@capgo/camera-preview';
const result = await CameraPreview.checkPermissions();// The result holds sensitive values: use it without logging it.requestPermissions
권한 요청카메라 (및 선택적으로 마이크) 권한을 요청합니다. 권한이 이미 허용되거나 거부된 경우, 현재 상태가 반환됩니다. 권한이 거부된 경우, 사용자에게 앱 설정으로 안내하는 플랫폼별 알림이 표시됩니다. showSettingsAlert 가로 화각을 얻습니다.
import { CameraPreview } from '@capgo/camera-preview';
const result = await CameraPreview.requestPermissions();// The result holds sensitive values: use it without logging it.getHorizontalFov
활성 카메라의 가로 화각을 얻습니다. 참고: 일부 기기에서는 추정치가 될 수 있습니다.지원하는 사진 크기를 얻습니다.
import { CameraPreview } from '@capgo/camera-preview';
const result = await CameraPreview.getHorizontalFov();console.log(result);getSupportedPictureSizes
모든 카메라의 지원하는 사진 크기를 얻습니다.권한이 거부된 경우, 플랫폼별 알림이 표시됩니다.
import { CameraPreview } from '@capgo/camera-preview';
const result = await CameraPreview.getSupportedPictureSizes();console.log(result);setFlashMode
setFlashMode활성 카메라의 플래시 모드를 설정합니다.
import { CameraPreview } from '@capgo/camera-preview';
await CameraPreview.setFlashMode({ flashMode: 'off' });flip
flip전면 카메라와 후면 카메라를 토글합니다.
import { CameraPreview } from '@capgo/camera-preview';
await CameraPreview.flip();setOpacity
setOpacity카메라 프리뷰의 투명도를 설정합니다.
import { CameraPreview } from '@capgo/camera-preview';
await CameraPreview.setOpacity({ opacity: 1.0 });stopRecordVideo
stopRecordVideo동영상 녹화를 중지합니다.
import { CameraPreview } from '@capgo/camera-preview';
const result = await CameraPreview.stopRecordVideo();console.log(result);startRecordVideo
시작 녹화 비디오비디오 녹화를 시작합니다.
import { CameraPreview } from '@capgo/camera-preview';
await CameraPreview.startRecordVideo({ parent: 'parent' });시작 실행 중
import { CameraPreview } from '@capgo/camera-preview';
const result = await CameraPreview.isRunning();console.log(result);getAvailableDevices
카메라 프리뷰가 현재 실행 중인지 확인합니다.시작 사용 가능한 장치
import { CameraPreview } from '@capgo/camera-preview';
const result = await CameraPreview.getAvailableDevices();console.log(result);getZoom
사용 가능한 카메라 장치를 모두 가져옵니다.시작 줌
import { CameraPreview } from '@capgo/camera-preview';
const result = await CameraPreview.getZoom();console.log(result);getZoomButtonValues
Section titled “줌 버튼 값 가져오기”빠른 Switching을 위한 줌 버튼 값을 반환합니다.
- iOS/Android: 초광각이 사용 가능하면 0.5 포함; 광각이 사용 가능하면 1과 2 포함; 망원경이 사용 가능하면 3 포함
- Web: 지원하지 않음
import { CameraPreview } from '@capgo/camera-preview';
const result = await CameraPreview.getZoomButtonValues();console.log(result);setZoom
Section titled “줌 설정”카메라 줌 레벨을 설정합니다.
import { CameraPreview } from '@capgo/camera-preview';
await CameraPreview.setZoom({ level: 1 });getFlashMode
Section titled “闪光模式获取”현재闪光模式을 가져옵니다.
import { CameraPreview } from '@capgo/camera-preview';
const result = await CameraPreview.getFlashMode();console.log(result);setDeviceId
Section titled “기기 ID 설정”활성 카메라를 지정된 카메라로 전환합니다. deviceId.
import { CameraPreview } from '@capgo/camera-preview';
await CameraPreview.setDeviceId({ deviceId: 'device-id-123' });getDeviceId
getDeviceId 섹션현재 바인드된 카메라 장치의 ID를 가져옵니다. 안드로이드에서 물리 렌즈 요청이 논리 카메라로 전환되는 경우 이 메서드는 바인드된 논리 카메라 ID를 반환합니다.
import { CameraPreview } from '@capgo/camera-preview';
const result = await CameraPreview.getDeviceId();console.log(result);getPreviewSize
getPreviewSize 섹션현재 미리보기 크기와 위치를 가져옵니다.
import { CameraPreview } from '@capgo/camera-preview';
const result = await CameraPreview.getPreviewSize();console.log(result);setPreviewSize
getPreviewSize 섹션미리보기 크기와 위치를 설정합니다.
import { CameraPreview } from '@capgo/camera-preview';
const result = await CameraPreview.setPreviewSize({ width: 1080, height: 1920,});console.log(result);setFocus
setFocus 섹션특정 영역에 카메라 초점을 설정합니다.
주의: 플러그인은 원시적인 탭-초점 동작 핸들러를 첨부하지 않습니다. HTML/JS에서 탭을 처리한 후 정규화된 좌표를 여기에 전달하세요.
import { CameraPreview } from '@capgo/camera-preview';
await CameraPreview.setFocus({ x: 1, y: 1,});deleteFile
삭제 파일지정된 디바이스의 절대 경로에 있는 파일을 삭제합니다.
임시로 생성된 이미지와 같은 임시 파일을 빠르게 삭제하려면 이 메서드를 사용하세요. storeToFile삭제 파일
import { CameraPreview } from '@capgo/camera-preview';
const result = await CameraPreview.deleteFile({ path: 'path/to/file' });console.log(result);getSafeAreaInsets
안전 영역 인셋 가져오기절대 경로에 있는 파일을 삭제합니다.
절대 경로에 있는 파일을 삭제합니다.
import { CameraPreview } from '@capgo/camera-preview';
const result = await CameraPreview.getSafeAreaInsets();console.log(result);getOrientation
절대 경로에 있는 파일을 삭제합니다. 임시로 생성된 이미지와 같은 임시 파일을 빠르게 삭제하려면 이 메서드를 사용하세요. 이 메서드는 웹에서 지원되지 않으며 예외를 발생시킵니다.기기의 현재 방향을 플랫폼 간 형식으로 가져옵니다.
import { CameraPreview } from '@capgo/camera-preview';
const result = await CameraPreview.getOrientation();console.log(result);getExposureModes
노출 모드활성 카메라에서 지원하는 노출 모드를 반환합니다. 모드는 '잠금', '자동', '연속', '사용자 정의' 등이 될 수 있습니다.
import { CameraPreview } from '@capgo/camera-preview';
const result = await CameraPreview.getExposureModes();console.log(result);getExposureMode
현재 노출 모드를 반환합니다.노출 모드를 설정합니다.
import { CameraPreview } from '@capgo/camera-preview';
const result = await CameraPreview.getExposureMode();console.log(result);setExposureMode
노출 보상 범위노출 보상 범위
import { CameraPreview } from '@capgo/camera-preview';
await CameraPreview.setExposureMode({ mode: 'AUTO' });getExposureCompensationRange
노출 보상 범위노출 보상 (EV 편차) 지원 범위 반환합니다.
import { CameraPreview } from '@capgo/camera-preview';
const result = await CameraPreview.getExposureCompensationRange();console.log(result);getExposureCompensation
getExposureCompensation현재 노출 보상 (EV 편차) 반환합니다.
import { CameraPreview } from '@capgo/camera-preview';
const result = await CameraPreview.getExposureCompensation();console.log(result);setExposureCompensation
setExposureCompensation노출 보상 (EV 편차) 설정합니다. 값은 지정된 범위에 맞춰 조정됩니다.
import { CameraPreview } from '@capgo/camera-preview';
await CameraPreview.setExposureCompensation({ value: 1 });타입 참조
CameraPreviewOptionsCameraPreviewOptions
카메라 프리뷰를 시작하기 위한 구성 옵션을 정의합니다.타입 참조
export interface CameraPreviewOptions { /** * The parent element to attach the video preview to. * @platform web */ parent?: string; /** * A CSS class name to add to the preview element. * @platform web */ className?: string; /** * The width of the preview in pixels. Defaults to the screen width. * @platform android, ios, web */ width?: number; /** * The height of the preview in pixels. Defaults to the screen height. * @platform android, ios, web */ height?: number; /** * The horizontal origin of the preview, in pixels. * @platform android, ios */ x?: number; /** * The vertical origin of the preview, in pixels. * @platform android, ios */ y?: number; /** * The aspect ratio of the camera preview, '4:3' or '16:9' or 'fill'. * Cannot be set if width or height is provided, otherwise the call will be rejected. * Use setPreviewSize to adjust size after starting. * * @since 2.0.0 */ aspectRatio?: '4:3' | '16:9'; /** * Controls how the camera preview fills the available space. * - 'contain': Fits the entire preview within the space, may show letterboxing (default). * - 'cover': Fills the entire space, may crop edges of the preview. * @default "contain" * @platform android, ios, web */ aspectMode?: 'cover' | 'contain'; /** * The grid overlay to display on the camera preview. * @default "none" * @since 2.1.0 */ gridMode?: GridMode; /** * Adjusts the y-position to account for safe areas (e.g., notches). * @platform ios * @default false */ includeSafeAreaInsets?: boolean; /** * If true, places the preview behind the webview. * @platform android * @default true */ toBack?: boolean; /** * Bottom padding for the preview, in pixels. * @platform android, ios */ paddingBottom?: number; /** * Whether to rotate the preview when the device orientation changes. * @platform ios * @default true */ rotateWhenOrientationChanged?: boolean; /** * The camera to use. * @default "rear" */ position?: CameraPosition | string; /** * If true, saves the captured image to a file and returns the file path. * If false, returns a base64 encoded string. * @default false */ storeToFile?: boolean; /** * If true, prevents the plugin from rotating the image based on EXIF data. * @platform android * @default false */ disableExifHeaderStripping?: boolean; /** * If true, disables the audio stream, preventing audio permission requests. * @default true */ disableAudio?: boolean; /** * If true, locks the device orientation while the camera is active. * @platform android * @default false */ lockAndroidOrientation?: boolean; /** * If true, allows the camera preview's opacity to be changed. * @platform android, web * @default false */ enableOpacity?: boolean;
/** * If true, disables the visual focus indicator when tapping to focus. * @platform android, ios * @default false */ disableFocusIndicator?: boolean; /** * The `deviceId` of the camera to use. If provided, `position` is ignored. * @platform ios */ deviceId?: string; /** * On Android, attempts to bind a physical camera directly when `deviceId` refers to a physical lens. * Disabled by default because OEM support is inconsistent; when false, Android keeps the current logical-camera fallback behavior. * @default false * @platform android */ enablePhysicalDeviceSelection?: boolean; /** * The initial zoom level when starting the camera preview. * If the requested zoom level is not available, the native plugin will reject. * @default 1.0 * @platform android, ios * @since 2.2.0 */ initialZoomLevel?: number; /** * The vertical positioning of the camera preview. * @default "center" * @platform android, ios, web * @since 2.3.0 */ positioning?: CameraPositioning; /** * If true, enables video capture capabilities when the camera starts. * @default false * @platform android * @since 7.11.0 */ enableVideoMode?: boolean; /** * If true, forces the camera to start/restart even if it's already running or busy. * This will kill the current camera session and start a new one, ignoring all state checks. * @default false * @platform android, ios, web */ force?: boolean; /** * Sets the quality of video for recording. * Options: 'low', 'medium', 'high' * @note On Android requires 'enableVideoMode' to be true * @note Will affect the entire preview stream for iOS * @platform ios, android * @default "high" */ videoQuality?: 'low' | 'medium' | 'high';}CameraPreviewPictureOptions
카메라 프리뷰 사진 옵션사진을 캡처하는 옵션을 정의합니다.
export interface CameraPreviewPictureOptions { /** * The maximum height of the picture in pixels. The image will be resized to fit within this height while maintaining aspect ratio. * If not specified the captured image will match the preview's visible area. */ height?: number; /** * The maximum width of the picture in pixels. The image will be resized to fit within this width while maintaining aspect ratio. * If not specified the captured image will match the preview's visible area. */ width?: number; /** * The quality of the captured image, from 0 to 100. * Does not apply to `.png` format. * @default 85 */ quality?: number; /** * The format of the captured image. * @default "jpeg" */ format?: PictureFormat; /** * If true, the captured image will be saved to the user's gallery. * @default false * @since 7.5.0 */ saveToGallery?: boolean; /** * If true, the plugin will attempt to add GPS location data to the image's EXIF metadata. * This may prompt the user for location permissions. * @default false * @since 7.6.0 */ withExifLocation?: boolean; /** * If true, the plugin will embed a timestamp in the top-right corner of the image. * @default false * @since 7.17.0 */ embedTimestamp?: boolean; /** * If true, the plugin will embed the current location in the top-right corner of the image. * Requires `withExifLocation` to be enabled. * @default false * @since 7.18.0 */ embedLocation?: boolean; /** * Sets the priority for photo quality vs. capture speed. * - "speed": Prioritizes faster capture times, may reduce image quality. * - "balanced": Aims for a balance between quality and speed. * - "quality": Prioritizes image quality, may reduce capture speed. * See https://developer.apple.com/documentation/avfoundation/avcapturephotosettings/photoqualityprioritization for details. * * @since 7.21.0 * @platform ios * @default "speed" */ photoQualityPrioritization?: 'speed' | 'balanced' | 'quality';}ExifData
EXIF 데이터이미지에서 추출된 EXIF 데이터를 나타냅니다.
export interface ExifData { [key: string]: any;}CameraSampleOptions
카메라 샘플 프레임 옵션카메라 프리뷰에서 샘플 프레임을 캡처하는 옵션을 정의합니다.
export interface CameraSampleOptions { /** * The quality of the captured sample, from 0 to 100. * @default 85 */ quality?: number;}CameraPreviewFlashMode
카메라 프리뷰 플래시 모드카메라의 사용 가능한 플래시 모드입니다. 'torch'는 연속적인 조명 모드입니다.
export type CameraPreviewFlashMode = 'off' | 'on' | 'auto' | 'torch';GridMode
그리드 모드export type GridMode = 'none' | '3x3' | '4x4';PermissionRequestOptions
권한 요청 옵션export interface PermissionRequestOptions { disableAudio?: boolean; showSettingsAlert?: boolean; title?: string; message?: string; openSettingsButtonTitle?: string; cancelButtonTitle?: string;}CameraPermissionStatus
카메라 권한 상태export interface CameraPermissionStatus { camera: PermissionState; microphone?: PermissionState;}SupportedPictureSizes
지원하는 사진 크기카메라 투명도 옵션
export interface SupportedPictureSizes { /** The camera direction ("front" or "rear"). */ facing: string; /** A list of supported picture sizes for this camera. */ supportedPictureSizes: PictureSize[];}CameraOpacityOptions
카메라가 특정 방향을 향해 지원하는 사진 크기를 나타냅니다.카메라 프리뷰의 투명도를 설정하는 옵션을 정의합니다.
export interface CameraOpacityOptions { /** * The opacity percentage, from 0.0 (fully transparent) to 1.0 (fully opaque). * @default 1.0 */ opacity?: number;}CameraDevice
카메라 디바이스장치에 설치된 물리 카메라 (예: 전면 카메라)를 나타냅니다.
export interface CameraDevice { /** A unique identifier for the camera device. */ deviceId: string; /** A human-readable name for the camera device. */ label: string; /** The physical position of the camera on the device. */ position: CameraPosition; /** A list of all available lenses for this camera device. */ lenses: CameraLens[]; /** The overall minimum zoom factor available across all lenses on this device. */ minZoom: number; /** The overall maximum zoom factor available across all lenses on this device. */ maxZoom: number; /** Identifies whether the device is a logical camera (composed of multiple physical lenses). */ isLogical: boolean;}LensInfo
렌즈 정보현재 활성 렌즈의 세부 정보를 나타냅니다.
export interface LensInfo { /** The focal length of the active lens in millimeters. */ focalLength: number; /** The device type of the active lens. */ deviceType: DeviceType; /** The base zoom ratio of the active lens (e.g., 0.5x, 1.0x). */ baseZoomRatio: number; /** The current digital zoom factor applied on top of the base zoom. */ digitalZoom: number;}진실의 근원
이 페이지는 플러그인의공개 __CAPGO_KEEP_0__이 업스트림에서 변경될 때 다시 싱크를 실행하세요. src/definitions.ts업스트림에서 pubic API이 변경되었을 때 다시 싱크를 실행하세요.
Getting Started
Getting Started만약에 시작하기 native 미디어 및 인터페이스 동작을 계획하고 싶다면 Using @capgo/camera-preview 카메라 프리뷰 플러그인 사용을 위해 @capgo/camera-preview 네이티브 기능을 사용합니다. @capgo/capacitor-라이브-활동 native 기능을 위한 @capgo/capacitor-live-활동의 사용 @capgo/capacitor-실시간 활동 @capgo/capacitor-실시간 활동 @capgo/capacitor-비디오 플레이어 for native 기능을 사용하기 위해 @capgo/capacitor-video-player를 사용합니다. @capgo/capacitor-video-player @capgo/capacitor-비디오 플레이어 구현 세부 사항에 대한 정보.