Skip to content

Commit

Permalink
updating web captureSample
Browse files Browse the repository at this point in the history
  • Loading branch information
nick-livefront committed Mar 30, 2021
1 parent 42757c2 commit afcf4c0
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 7 deletions.
12 changes: 6 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -203,7 +203,7 @@ CameraPreview.hide();
<!-- <info>Take the picture. If width and height are not specified or are 0 it will use the defaults. If width and height are specified, it will choose a supported photo size that is closest to width and height specified and has closest aspect ratio to the preview. The argument `quality` defaults to `85` and specifies the quality/compression value: `0=max compression`, `100=max quality`.</info><br/> -->

```javascript
import { CameraPreviewFlashMode } from 'c@capacitor-community/camera-preview';
import { CameraPreviewFlashMode } from '@capacitor-community/camera-preview';

const cameraPreviewPictureOptions: CameraPreviewPictureOptions = {
quality: 50
Expand All @@ -222,16 +222,16 @@ const base64PictureData = result.value;
|----------|---------------|----------------------------------------------------------------------|
| quality | number | (optional) The picture quality, 0 - 100, default 85 |

<info>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`.</info><br/>
<info>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`.</info><br/>

```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
Expand Down
7 changes: 7 additions & 0 deletions src/definitions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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[]
}>;
Expand Down
12 changes: 11 additions & 1 deletion src/web.ts
Original file line number Diff line number Diff line change
@@ -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() {
Expand Down Expand Up @@ -88,6 +94,10 @@ export class CameraPreviewWeb extends WebPlugin implements CameraPreviewPlugin {
});
}

async captureSample(_options: CameraSampleOptions): Promise<any> {
return this.capture(_options);
}

async getSupportedFlashModes(): Promise<{
result: CameraPreviewFlashMode[]
}> {
Expand Down

0 comments on commit afcf4c0

Please sign in to comment.