Getting Started
インストール手順とこのプラグインの全マークダウンガイドを含む設定用の質問をコピーしてください。
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アシストセットアップを使用してプラグインをインストールできます。AIツールにCapgoスキルを追加するには、以下のコマンドを使用してください:
npx skills add https://github.com/Cap-go/capgo-skills --skill capacitor-plugins次に、以下のプロンプトを使用してください:
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 syncインポート
「インポート」のセクションimport { CameraPreview } from '@capgo/camera-preview';API オーバービュー
「API オーバービュー」のセクションstart
「start」のセクションカメラプレビューを開始します。
import { CameraPreview } from '@capgo/camera-preview';
await CameraPreview.start({} as CameraPreviewOptions);カメラプレビューを停止します。
import { CameraPreview } from '@capgo/camera-preview';
await CameraPreview.stop();capture
Section titled “capture”カメラから写真を撮ります。
もし storeToFile __CAPGO_KEEP_0__ true がプレビューを開始したときに設定されていた場合、返される
value は、デバイス上の絶対ファイルパスではなくbase64文字列になります。getBase64FromFilePathを使用して、ファイルパスからbase64文字列を取得してください。
import { CameraPreview } from '@capgo/camera-preview';
await CameraPreview.capture({} as CameraPreviewPictureOptions);captureSample
Section titled “captureSample”カメラプレビューのストリームから1フレームをキャプチャします。
import { CameraPreview } from '@capgo/camera-preview';
await CameraPreview.captureSample({} as CameraSampleOptions);getSupportedFlashModes
__CAPGO_KEEP_1__ “getSupportedFlashModes”__CAPGO_KEEP_2__ “getSupportedFlashModes”
import { CameraPreview } from '@capgo/camera-preview';
await CameraPreview.getSupportedFlashModes();setAspectRatio
__CAPGO_KEEP_1__ “setAspectRatio”__CAPGO_KEEP_2__ アスペクト比を設定します。
import { CameraPreview } from '@capgo/camera-preview';
await CameraPreview.setAspectRatio({} as { aspectRatio: '4:3' | '16:9'; x?: number; y?: number });getAspectRatio
__CAPGO_KEEP_1__ “getAspectRatio”__CAPGO_KEEP_2__ カメラプレビューの現在のアスペクト比を取得します。
import { CameraPreview } from '@capgo/camera-preview';
await CameraPreview.getAspectRatio();setGridMode
__CAPGO_KEEP_1__ “setGridMode”__CAPGO_KEEP_2__ カメラプレビューのオーバーレイのグリッドモードを設定します。
import { CameraPreview } from '@capgo/camera-preview';
await CameraPreview.setGridMode({} as { gridMode: GridMode });getGridMode
「getGridMode」セクションカメラプレビューOverlayの現在のグリッドモードを取得します。
import { CameraPreview } from '@capgo/camera-preview';
await CameraPreview.getGridMode();checkPermissions
「checkPermissions」セクションカメラ(オプションでマイク)許可状態を確認します。システムダイアログを提示せずに。
import { CameraPreview } from '@capgo/camera-preview';
await CameraPreview.checkPermissions();requestPermissions
「requestPermissions」セクションカメラ(オプションでマイク)許可を要求します。許可が既に付与されたり拒否された場合は、現在の状態を返します。許可が拒否されている場合にtrueが指定されると、プラットフォーム固有のアラートが表示されます。 showSettingsAlert クリップボードにコピー
import { CameraPreview } from '@capgo/camera-preview';
await CameraPreview.requestPermissions();getHorizontalFov
protectedTokens__CAPGO_KEEP_0__の水平視野を取得します。 注意: 一部のデバイスでは、推定値になります。
import { CameraPreview } from '@capgo/camera-preview';
await CameraPreview.getHorizontalFov();getSupportedPictureSizes
__CAPGO_KEEP_1____CAPGO_KEEP_0__のすべてのカメラのサポートサイズを取得します。
import { CameraPreview } from '@capgo/camera-preview';
await CameraPreview.getSupportedPictureSizes();setFlashMode
__CAPGO_KEEP_1____CAPGO_KEEP_0__のアクティブカメラのフラッシュモードを設定します。
import { CameraPreview } from '@capgo/camera-preview';
await CameraPreview.setFlashMode({} as { flashMode: CameraPreviewFlashMode | string });flip
__CAPGO_KEEP_1____CAPGO_KEEP_0__を切り替えます。
import { CameraPreview } from '@capgo/camera-preview';
await CameraPreview.flip();setOpacity
__CAPGO_KEEP_1____CAPGO_KEEP_0__をカメラプレビューの不透明度に設定します。
import { CameraPreview } from '@capgo/camera-preview';
await CameraPreview.setOpacity({} as CameraOpacityOptions);stopRecordVideo
「stopRecordVideo」セクション__CAPGO_KEEP_2__を実行中のビデオレコーディングを停止します。
import { CameraPreview } from '@capgo/camera-preview';
await CameraPreview.stopRecordVideo();startRecordVideo
「startRecordVideo」セクション__CAPGO_KEEP_0__をビデオレコーディングを開始します。
import { CameraPreview } from '@capgo/camera-preview';
await CameraPreview.startRecordVideo({} as CameraPreviewOptions);isRunning
「isRunning」セクション__CAPGO_KEEP_0__をカメラプレビューが現在実行中かどうかを確認します。
import { CameraPreview } from '@capgo/camera-preview';
await CameraPreview.isRunning();getAvailableDevices
「getAvailableDevices」セクションすべての利用可能なカメラデバイスを取得します。
import { CameraPreview } from '@capgo/camera-preview';
await CameraPreview.getAvailableDevices();getZoom
「getZoom」セクション現在のズーム状態を取得します。最小値/最大値と現在のレンズ情報を含みます。
import { CameraPreview } from '@capgo/camera-preview';
await CameraPreview.getZoom();getZoomButtonValues
「getZoomButtonValues」セクションズームボタンの値を取得します。
- iOS/Android: 超広角が利用可能の場合、0.5を含みます。広角が利用可能の場合、1と2を含みます。望遠レンズが利用可能の場合、3を含みます。
- Web: 不対応
import { CameraPreview } from '@capgo/camera-preview';
await CameraPreview.getZoomButtonValues();setZoom
「setZoom」セクションカメラのズームレベルを設定します。
import { CameraPreview } from '@capgo/camera-preview';
await CameraPreview.setZoom({} as { level: number; ramp?: boolean; autoFocus?: boolean });getFlashMode
「getFlashMode」セクション現在のフラッシュモードを取得します。
import { CameraPreview } from '@capgo/camera-preview';
await CameraPreview.getFlashMode();setDeviceId
「setDeviceId」セクション指定されたカメラに切り替えます。 deviceId.
import { CameraPreview } from '@capgo/camera-preview';
await CameraPreview.setDeviceId({} as { deviceId: string });getDeviceId
「getDeviceId」セクション現在バインドされているカメラデバイスのIDを取得します。 Androidの場合、物理レンズのリクエストが論理カメラにフォールバックした場合、このIDは論理カメラのIDになります。
import { CameraPreview } from '@capgo/camera-preview';
await CameraPreview.getDeviceId();getPreviewSize
「getPreviewSize」セクション現在のプレビューのサイズと位置を取得します。
import { CameraPreview } from '@capgo/camera-preview';
await CameraPreview.getPreviewSize();setPreviewSize
「プレビューのサイズを設定」セクションプレビューのサイズと位置を設定します。
import { CameraPreview } from '@capgo/camera-preview';
await CameraPreview.setPreviewSize({} as { x?: number; y?: number; width: number; height: number });setFocus
「フォーカスを設定」セクションプレビュー内の特定のポイントにカメラの焦点を設定します。
注: プラグインは、ネイティブのタップでフォーカスするジェスチャーハンドラーを追加しません。タップを処理するには、HTML/JS (例:Overlay UI) にタップを処理するコードを追加し、ここに正規化された座標を渡してください。
import { CameraPreview } from '@capgo/camera-preview';
await CameraPreview.setFocus({} as { x: number; y: number });deleteFile
「ファイルを削除」セクションデバイス上の絶対パスで指定されたファイルを削除します。
このメソッドを使用して、
で作成された一時的な画像を迅速に削除できます。
ウェブ上では、このメソッドはサポートされていません。エラーを投げます。 storeToFileコピー
import { CameraPreview } from '@capgo/camera-preview';
await CameraPreview.deleteFile({} as { path: string });getSafeAreaInsets
Section titled “getSafeAreaInsets”デバイスのセーフエリアのインセットを取得します。 オリエンテーションに応じたノッチ/カメラカットアウトのインセットと現在のオリエンテーションを返します。 ポートレートモードの場合:上部のインセット(上部のノッチ)を返します。 ランドスケープモードの場合:左側のインセット(ノッチが側面に移動)を返します。 この機能は、すべてのモダンな電話で使用されているカットアウトエリア(ノッチ、パンチホールなど)を特定的にターゲットにします。
Android:dp(論理ピクセル)で値が返されます。 iOS:ステータスバーを除いた物理ピクセルで値が返されます(純粋なノッチ/カットアウトサイズのみ)。
import { CameraPreview } from '@capgo/camera-preview';
await CameraPreview.getSafeAreaInsets();getOrientation
Section titled “getOrientation”デバイスの現在のオリエンテーションをクロスプラットフォーム形式で取得します。
import { CameraPreview } from '@capgo/camera-preview';
await CameraPreview.getOrientation();getExposureModes
Section titled “getExposureModes”現在のカメラでサポートされている露光モードを返します。 モードには ‘locked’、 ‘auto’、 ‘continuous’、 ‘custom’ が含まれます。
import { CameraPreview } from '@capgo/camera-preview';
await CameraPreview.getExposureModes();getExposureMode
Section titled “getExposureMode”現在の露光モードを返します。
import { CameraPreview } from '@capgo/camera-preview';
await CameraPreview.getExposureMode();setExposureMode
__CAPGO_KEEP_1____CAPGO_KEEP_2__
import { CameraPreview } from '@capgo/camera-preview';
await CameraPreview.setExposureMode({} as { mode: ExposureMode });getExposureCompensationRange
__CAPGO_KEEP_1____CAPGO_KEEP_3__
import { CameraPreview } from '@capgo/camera-preview';
await CameraPreview.getExposureCompensationRange();getExposureCompensation
__CAPGO_KEEP_1____CAPGO_KEEP_4__
import { CameraPreview } from '@capgo/camera-preview';
await CameraPreview.getExposureCompensation();setExposureCompensation
__CAPGO_KEEP_1____CAPGO_KEEP_5__
import { CameraPreview } from '@capgo/camera-preview';
await CameraPreview.setExposureCompensation({} as { value: number });型式リファレンス
型式リファレンスCameraPreviewOptions
カメラプレビューの設定__CAPGO_KEEP_0__
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
__CAPGO_KEEP_0__EXIFデータ
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
__CAPGO_KEEP_0____CAPGO_KEEP_0__
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
Section titled “サポートされたピクチャサイズ”__CAPGO_KEEP_0__
export interface SupportedPictureSizes { /** The camera direction ("front" or "rear"). */ facing: string; /** A list of supported picture sizes for this camera. */ supportedPictureSizes: PictureSize[];}CameraOpacityOptions
Section titled “カメラの不透明度オプション”__CAPGO_KEEP_0__
export interface CameraOpacityOptions { /** * The opacity percentage, from 0.0 (fully transparent) to 1.0 (fully opaque). * @default 1.0 */ opacity?: number;}CameraDevice
Section titled “カメラデバイス”__CAPGO_KEEP_0__
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
Section titled “レンズ情報”__CAPGO_KEEP_0__
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;}真実の源
「真実の源」というセクションこのページはプラグインの src/definitions.tsパブリック API がアップストリームで変更された場合に再度 Sync を実行してください。
Getting Started から続けてください。
「Getting Started から続けてください」というセクションCapacitor を使用している場合 Getting Started native media と interface の動作を計画する場合、Capacitor を Using @capgo/camera-preview Using @capgo/camera-preview の native capability について Using @capgo/capacitor-live-activities for the native capability in Using @capgo/capacitor-live-activities, @capgo/capacitor-live-activities for the implementation detail in @capgo/capacitor-live-activities, Using @capgo/capacitor-video-player for the native capability in Using @capgo/capacitor-video-player, and @capgo/capacitor-video-player for the implementation detail in @capgo/capacitor-video-player.