diff --git a/README.md b/README.md index 73995ebf..c2585ac2 100644 --- a/README.md +++ b/README.md @@ -146,7 +146,7 @@ ion-content { --background: transparent; } ``` -Take into account that this will make transparent all ion-content on application, if you want to show camera preview only in one page, just add a cutom class to your ion-content and make it transparent: +Take into account that this will make transparent all ion-content on application, if you want to show camera preview only in one page, just add a custom class to your ion-content and make it transparent: ```css .my-custom-camera-preview-content { @@ -203,7 +203,7 @@ CameraPreview.hide(); ```javascript -import { CameraPreviewFlashMode } from 'c@capacitor-community/camera-preview'; +import { CameraPreviewFlashMode } from '@capacitor-community/camera-preview'; const cameraPreviewPictureOptions: CameraPreviewPictureOptions = { quality: 50 @@ -222,16 +222,16 @@ const base64PictureData = result.value; |----------|---------------|----------------------------------------------------------------------| | quality | number | (optional) The picture quality, 0 - 100, default 85 | -Captures a sample image from the video stream. This can be used to perform real-time analysis on the current frame in the video. The argument `quality` defaults to `85` and specifies the quality/compression value: `0=max compression`, `100=max quality`.
+Captures a sample image from the video stream. Only for Android and iOS, web implementation falls back to `capture` method. This can be used to perform real-time analysis on the current frame in the video. The argument `quality` defaults to `85` and specifies the quality/compression value: `0=max compression`, `100=max quality`.
```javascript -import { CameraPreviewFlashMode } from 'c@capacitor-community/camera-preview'; +import { CameraSampleOptions } from '@capacitor-community/camera-preview'; -const cameraPreviewPictureOptions: CameraPreviewPictureOptions = { +const cameraSampleOptions: CameraSampleOptions = { quality: 50 }; -const result = await CameraPreview.captureSample(cameraPreviewPictureOptions); +const result = await CameraPreview.captureSample(cameraSampleOptions); const base64PictureData = result.value; // do something with base64PictureData diff --git a/src/definitions.ts b/src/definitions.ts index c9fa20e2..df8ed7fe 100644 --- a/src/definitions.ts +++ b/src/definitions.ts @@ -43,12 +43,19 @@ export interface CameraPreviewPictureOptions { /** The picture quality, 0 - 100, default 85 */ quality?: number; } + +export interface CameraSampleOptions { + /** The picture quality, 0 - 100, default 85 */ + quality?: number; +} + export type CameraPreviewFlashMode = 'off' | 'on' | 'auto' | 'red-eye' | 'torch'; export interface CameraPreviewPlugin { start(options: CameraPreviewOptions): Promise<{}>; stop(): Promise<{}>; capture(options: CameraPreviewPictureOptions): Promise<{ value: string }>; + captureSample(options: CameraSampleOptions): Promise<{ value: string }>; getSupportedFlashModes(): Promise<{ result: CameraPreviewFlashMode[] }>; diff --git a/src/web.ts b/src/web.ts index 5a7d4206..7f03cf13 100644 --- a/src/web.ts +++ b/src/web.ts @@ -1,5 +1,11 @@ import { WebPlugin } from "@capacitor/core"; -import { CameraPreviewOptions, CameraPreviewPictureOptions, CameraPreviewPlugin, CameraPreviewFlashMode } from "./definitions"; +import { + CameraPreviewOptions, + CameraPreviewPictureOptions, + CameraPreviewPlugin, + CameraPreviewFlashMode, + CameraSampleOptions +} from "./definitions"; export class CameraPreviewWeb extends WebPlugin implements CameraPreviewPlugin { constructor() { @@ -88,6 +94,10 @@ export class CameraPreviewWeb extends WebPlugin implements CameraPreviewPlugin { }); } + async captureSample(_options: CameraSampleOptions): Promise { + return this.capture(_options); + } + async getSupportedFlashModes(): Promise<{ result: CameraPreviewFlashMode[] }> {