Zum Inhalt springen

Getting Started

GitHub

Sie können unsere AI-gestützte Einrichtung verwenden, um das Plugin zu installieren. Fügen Sie die Capgo-Fähigkeiten zu Ihrem AI-Tool hinzu, indem Sie die folgende Befehlszeile verwenden:

Terminal-Fenster
npx skills add https://github.com/Cap-go/capgo-skills --skill capacitor-plugins

Dann verwenden Sie die folgende Anfrage:

Use the `capacitor-plugins` skill from `Cap-go/capgo-skills` to install the `@capgo/camera-preview` plugin in my project.

Wenn Sie die manuelle Einrichtung bevorzugen, installieren Sie das Plugin, indem Sie die folgenden Befehle ausführen und die unten angegebenen Plattform-spezifischen Anweisungen befolgen:

Terminal-Fenster
bun add @capgo/camera-preview
bunx cap sync
import { CameraPreview } from '@capgo/camera-preview';

Die Kamera-Vorschau startet.

import { CameraPreview } from '@capgo/camera-preview';
await CameraPreview.start({} as CameraPreviewOptions);

Die Kamera-Vorschau stoppt.

import { CameraPreview } from '@capgo/camera-preview';
await CameraPreview.stop();

Ermittelt ein Bild vom Kamera.

Wenn storeToFile war auf true gestellt, wenn die Voransicht gestartet wurde, wird anstelle einer Base64-Zeichenfolge ein absoluter Dateipfad auf dem Gerät zurückgegeben. Verwenden Sie getBase64FromFilePath, um die Base64-Zeichenfolge aus dem Dateipfad zu erhalten. value Zwischenablage kopieren

import { CameraPreview } from '@capgo/camera-preview';
await CameraPreview.capture({} as CameraPreviewPictureOptions);

Zwischenablage kopieren

import { CameraPreview } from '@capgo/camera-preview';
await CameraPreview.captureSample({} as CameraSampleOptions);

Zwischenablage kopieren

import { CameraPreview } from '@capgo/camera-preview';
await CameraPreview.getSupportedFlashModes();

Setzen Sie den Aspektverhältnis der Kameravorschau.

import { CameraPreview } from '@capgo/camera-preview';
await CameraPreview.setAspectRatio({} as { aspectRatio: '4:3' | '16:9'; x?: number; y?: number });

Ermittelt das aktuelle Aspektverhältnis der Kameravorschau.

import { CameraPreview } from '@capgo/camera-preview';
await CameraPreview.getAspectRatio();

Setzt den Rastermodus der Kameravorschau-Überlagerung.

import { CameraPreview } from '@capgo/camera-preview';
await CameraPreview.setGridMode({} as { gridMode: GridMode });

Ermittelt den aktuellen Rastermodus der Kameravorschau-Überlagerung.

import { CameraPreview } from '@capgo/camera-preview';
await CameraPreview.getGridMode();

Überprüft den aktuellen Zustand der Kamera- (und optional der Mikrofon-) Berechtigung ohne das Systemdialog zu öffnen.

import { CameraPreview } from '@capgo/camera-preview';
await CameraPreview.checkPermissions();

Bittet um Kamera- (und optional Mikrofon-) Berechtigungen. Wenn Berechtigungen bereits erteilt oder abgelehnt wurden, wird der aktuelle Status ohne Aufforderung zurückgegeben. Wenn showSettingsAlert wahr ist und Berechtigungen abgelehnt wurden, wird eine plattform-spezifische Warnung präsentiert, die den Benutzer zu den Einstellungen der App leitet.

import { CameraPreview } from '@capgo/camera-preview';
await CameraPreview.requestPermissions();

Ermittelt den horizontalen Gesichtswinkel für die aktive Kamera. Hinweis: Dies kann eine Schätzung auf einigen Geräten sein.

import { CameraPreview } from '@capgo/camera-preview';
await CameraPreview.getHorizontalFov();

Ermittelt die unterstützten Bildgrößen für alle Kameras.

import { CameraPreview } from '@capgo/camera-preview';
await CameraPreview.getSupportedPictureSizes();

Setzt die Blitzmodus für die aktive Kamera.

import { CameraPreview } from '@capgo/camera-preview';
await CameraPreview.setFlashMode({} as { flashMode: CameraPreviewFlashMode | string });

Schaltet zwischen der Vorder- und Rückkamera um.

import { CameraPreview } from '@capgo/camera-preview';
await CameraPreview.flip();

Setzt die Transparenz der Kamera-Vorschau.

import { CameraPreview } from '@capgo/camera-preview';
await CameraPreview.setOpacity({} as CameraOpacityOptions);

Beendet ein laufendes Videoaufnahmeverfahren.

import { CameraPreview } from '@capgo/camera-preview';
await CameraPreview.stopRecordVideo();

Einen Videoaufzeichnungsprozess startet.

import { CameraPreview } from '@capgo/camera-preview';
await CameraPreview.startRecordVideo({} as CameraPreviewOptions);

Überprüft, ob die Kamera-Vorschau derzeit läuft.

import { CameraPreview } from '@capgo/camera-preview';
await CameraPreview.isRunning();

Alle verfügbaren Kamera-Geräte abruft.

import { CameraPreview } from '@capgo/camera-preview';
await CameraPreview.getAvailableDevices();

Den aktuellen Zoom-Zustand, einschließlich Mindest- und Maximalwert sowie aktuelle Objektiv-Informationen, abruft.

import { CameraPreview } from '@capgo/camera-preview';
await CameraPreview.getZoom();

Gibt die Werte der Zoom-Taste für schnelles Wechseln zurück.

  • iOS/Android: enthält 0,5, wenn Ultra-Wide verfügbar ist; 1 und 2, wenn breit verfügbar ist; 3, wenn Telephoto verfügbar ist
  • Web: nicht unterstützt
import { CameraPreview } from '@capgo/camera-preview';
await CameraPreview.getZoomButtonValues();

Setzt die Zoom-Einstellung der Kamera.

import { CameraPreview } from '@capgo/camera-preview';
await CameraPreview.setZoom({} as { level: number; ramp?: boolean; autoFocus?: boolean });

Gibt den aktuellen Blitzmodus zurück.

import { CameraPreview } from '@capgo/camera-preview';
await CameraPreview.getFlashMode();

Wechselt die aktive Kamera auf die mit der angegebenen deviceId.

import { CameraPreview } from '@capgo/camera-preview';
await CameraPreview.setDeviceId({} as { deviceId: string });

Ermittelt die ID des Kamera-Geräts, das derzeit gebunden ist. Bei Android-Fällen, wenn eine physische-Linsen-Anfrage auf eine logische Kamera zurückfällt, gibt dies die ID der gebundenen logischen Kamera zurück.

import { CameraPreview } from '@capgo/camera-preview';
await CameraPreview.getDeviceId();

Ermittelt die aktuelle Vorschau-Größe und -Position.

import { CameraPreview } from '@capgo/camera-preview';
await CameraPreview.getPreviewSize();

Setzt die Vorschau-Größe und -Position.

import { CameraPreview } from '@capgo/camera-preview';
await CameraPreview.setPreviewSize({} as { x?: number; y?: number; width: number; height: number });

Setzt den Kamerafokus auf einen bestimmten Punkt im Vorschau-Bild.

Hinweis: Das Plugin bindet keine native Berührungszu-Fokus-Gesten-Handler. Behandeln Sie Berührungen in Ihrer HTML/JS (z.B. auf der überlagerten UI), dann übergeben Sie normalisierte Koordinaten hier.

import { CameraPreview } from '@capgo/camera-preview';
await CameraPreview.setFocus({} as { x: number; y: number });

Löscht ein Datei an der gegebenen absoluten Pfad auf dem Gerät. Verwenden Sie dies, um temporäre Bilder schnell zu löschen, die mit . Erstellt wurden. Auf dem Web wird dies nicht unterstützt und wird einen Fehler auslösen. storeToFileZwischenablage kopieren

import { CameraPreview } from '@capgo/camera-preview';
await CameraPreview.deleteFile({} as { path: string });

Android: Werte werden in dp (logische Pixel) zurückgegeben. iOS: Werte werden in physischen Pixeln, ohne Statusleiste (nur reine Notch-Größe), zurückgegeben.

Zwischenablage kopieren

import { CameraPreview } from '@capgo/camera-preview';
await CameraPreview.getSafeAreaInsets();

Ermittelt die aktuelle Geräteorientierung in einer plattformübergreifenden Format.

import { CameraPreview } from '@capgo/camera-preview';
await CameraPreview.getOrientation();

Gibt die von der aktiven Kamera unterstützten Belichtungsmodi zurück. Die Modi können ‘eingefroren’, ‘automatisch’, ‘fortlaufend’, ‘benutzerdefiniert’ sein.

import { CameraPreview } from '@capgo/camera-preview';
await CameraPreview.getExposureModes();

Gibt den aktuellen Belichtungsmodus zurück.

import { CameraPreview } from '@capgo/camera-preview';
await CameraPreview.getExposureMode();

Setzt den Belichtungsmodus.

import { CameraPreview } from '@capgo/camera-preview';
await CameraPreview.setExposureMode({} as { mode: ExposureMode });

Gibt den Bereich der unterstützten Belichtungsanpassung (EV-Verschiebung) zurück.

import { CameraPreview } from '@capgo/camera-preview';
await CameraPreview.getExposureCompensationRange();

Gibt die aktuelle Belichtungsanpassung (EV-Verschiebung) zurück.

import { CameraPreview } from '@capgo/camera-preview';
await CameraPreview.getExposureCompensation();

Setzt die Belichtungsanpassung (EV-Verschiebung). Der Wert wird auf den Bereich begrenzt.

import { CameraPreview } from '@capgo/camera-preview';
await CameraPreview.setExposureCompensation({} as { value: number });

Legt die Konfigurationsoptionen für das Starten der Kamera-Vorschau fest.

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';
}

Legt die Optionen für die Aufnahme einer Bild fest.

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';
}

Stellt die EXIF-Daten dar, die aus einem Bild extrahiert wurden.

export interface ExifData {
[key: string]: any;
}

Legt die Optionen für die Aufnahme eines Sample-Frames aus der Kamera-Vorschau fest.

export interface CameraSampleOptions {
/**
* The quality of the captured sample, from 0 to 100.
* @default 85
*/
quality?: number;
}

Die verfügbaren Blitzmodi für die Kamera. ‘Torch’ ist ein kontinuierlicher Lichtmodus.

export type CameraPreviewFlashMode = 'off' | 'on' | 'auto' | 'torch';
export type GridMode = 'none' | '3x3' | '4x4';
export interface PermissionRequestOptions {
disableAudio?: boolean;
showSettingsAlert?: boolean;
title?: string;
message?: string;
openSettingsButtonTitle?: string;
cancelButtonTitle?: string;
}
export interface CameraPermissionStatus {
camera: PermissionState;
microphone?: PermissionState;
}

Die unterstützten Bildgrößen für eine Kamera, die in eine bestimmte Richtung zeigt.

export interface SupportedPictureSizes {
/** The camera direction ("front" or "rear"). */
facing: string;
/** A list of supported picture sizes for this camera. */
supportedPictureSizes: PictureSize[];
}

Definiert die Optionen für die Einstellung der Opazität der Kamera-Vorschau.

export interface CameraOpacityOptions {
/**
* The opacity percentage, from 0.0 (fully transparent) to 1.0 (fully opaque).
* @default 1.0
*/
opacity?: number;
}

Stellt ein physisches Kamera-Gerät auf dem Gerät dar (z.B. die Vorderkamera).

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;
}

Stellt die detaillierten Informationen der derzeit aktiven Linse dar.

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;
}

Diese Seite wird von dem Plugin generiert. src/definitions.tsLäuft die Synchronisation erneut, wenn die öffentliche API upstream geändert wird.

Wenn Sie native Medien und Schnittstellenverhalten planen, verbinden Sie es mit Anfang um native Medien und Schnittstellenverhalten zu planen, verbinden Sie es mit Verwenden Sie @capgo/camera-preview um die native Fähigkeit in Verwenden Sie @capgo/camera-preview zu nutzen Verwenden Sie @capgo/capacitor-live-activities um die native Fähigkeit in Verwenden Sie @capgo/capacitor-live-activities zu nutzen @capgo/capacitor-live-activities um die Implementierungsdetails in @capgo/capacitor-live-activities zu nutzen Verwenden Sie @capgo/capacitor-video-player für die native Fähigkeit in @capgo/capacitor-video-player und @capgo/capacitor-video-player für die Implementierungsdetail in @capgo/capacitor-video-player.