Socket
Socket
Sign inDemoInstall

capacitor-plugin-camera

Package Overview
Dependencies
6
Maintainers
1
Versions
12
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    capacitor-plugin-camera

A capacitor camera plugin


Version published
Weekly downloads
14
increased by75%
Maintainers
1
Install size
2.29 MB
Created
Weekly downloads
 

Readme

Source

capacitor-plugin-camera

A capacitor camera plugin.

Online demo

Supported Platforms

  • Android (based on CameraX)
  • iOS (based on AVCaptureSession)
  • Web (based on getUserMedia with Dynamsoft Camera Enhancer)

Install

npm install capacitor-plugin-camera
npx cap sync

Get Bitmap/UIImage via Reflection

If you are developing a plugin, you can use reflection to get the camera frames as Bitmap or UIImage on the native side.

Java:

Class cls = Class.forName("com.tonyxlh.capacitor.camera.CameraPreviewPlugin");
Method m = cls.getMethod("getBitmap",null);
Bitmap bitmap = (Bitmap) m.invoke(null, null);

Objective-C:

- (UIImage*)getUIImage{
    UIImage *image = ((UIImage* (*)(id, SEL))objc_msgSend)(objc_getClass("CameraPreviewPlugin"), sel_registerName("getBitmap"));
    return image;
}

You have to call saveFrame beforehand.

Declare Permissions

To use camera and microphone, we need to declare permissions.

Add the following to Android's AndroidManifest.xml:

<uses-permission android:name="android.permission.CAMERA" />
<uses-permission android:name="android.permission.RECORD_AUDIO" />

Add the following to iOS's Info.plist:

<key>NSCameraUsageDescription</key>
<string>For camera usage</string>
<key>NSMicrophoneUsageDescription</key>
<string>For video recording</string>

FAQ

Why I cannot see the camera?

For native platforms, the plugin puts the native camera view behind the webview and sets the webview as transparent so that we can display HTML elements above the camera.

You may need to add the style below on your app's HTML or body element to avoid blocking the camera view:

ion-content {
  --background: transparent;
}

API

initialize()

initialize() => Promise<void>

getResolution()

getResolution() => Promise<{ resolution: string; }>

Returns: Promise<{ resolution: string; }>


setResolution(...)

setResolution(options: { resolution: number; }) => Promise<void>
ParamType
options{ resolution: number; }

getAllCameras()

getAllCameras() => Promise<{ cameras: string[]; }>

Returns: Promise<{ cameras: string[]; }>


getSelectedCamera()

getSelectedCamera() => Promise<{ selectedCamera: string; }>

Returns: Promise<{ selectedCamera: string; }>


selectCamera(...)

selectCamera(options: { cameraID: string; }) => Promise<void>
ParamType
options{ cameraID: string; }

setScanRegion(...)

setScanRegion(options: { region: ScanRegion; }) => Promise<void>
ParamType
options{ region: ScanRegion; }

setZoom(...)

setZoom(options: { factor: number; }) => Promise<void>
ParamType
options{ factor: number; }

setFocus(...)

setFocus(options: { x: number; y: number; }) => Promise<void>
ParamType
options{ x: number; y: number; }

setDefaultUIElementURL(...)

setDefaultUIElementURL(url: string) => Promise<void>

Web Only

ParamType
urlstring

setElement(...)

setElement(ele: any) => Promise<void>

Web Only

ParamType
eleany

startCamera()

startCamera() => Promise<void>

stopCamera()

stopCamera() => Promise<void>

takeSnapshot(...)

takeSnapshot(options: { quality?: number; }) => Promise<{ base64: string; }>

take a snapshot as base64.

ParamType
options{ quality?: number; }

Returns: Promise<{ base64: string; }>


saveFrame()

saveFrame() => Promise<{ success: boolean; }>

save a frame internally. Android and iOS only.

Returns: Promise<{ success: boolean; }>


takeSnapshot2(...)

takeSnapshot2(options: { canvas: HTMLCanvasElement; maxLength?: number; }) => Promise<{ scaleRatio?: number; }>

take a snapshot on to a canvas. Web Only

ParamType
options{ canvas: any; maxLength?: number; }

Returns: Promise<{ scaleRatio?: number; }>


takePhoto(...)

takePhoto(options: { pathToSave?: string; includeBase64?: boolean; }) => Promise<{ path?: string; base64?: string; blob?: Blob; }>
ParamType
options{ pathToSave?: string; includeBase64?: boolean; }

Returns: Promise<{ path?: string; base64?: string; blob?: any; }>


toggleTorch(...)

toggleTorch(options: { on: boolean; }) => Promise<void>
ParamType
options{ on: boolean; }

getOrientation()

getOrientation() => Promise<{ "orientation": "PORTRAIT" | "LANDSCAPE"; }>

get the orientation of the device.

Returns: Promise<{ orientation: 'PORTRAIT' | 'LANDSCAPE'; }>


startRecording()

startRecording() => Promise<void>

stopRecording(...)

stopRecording(options: { includeBase64?: boolean; }) => Promise<{ path?: string; base64?: string; blob?: Blob; }>
ParamType
options{ includeBase64?: boolean; }

Returns: Promise<{ path?: string; base64?: string; blob?: any; }>


setLayout(...)

setLayout(options: { top: string; left: string; width: string; height: string; }) => Promise<void>
ParamType
options{ top: string; left: string; width: string; height: string; }

requestCameraPermission()

requestCameraPermission() => Promise<void>

requestMicroPhonePermission()

requestMicroPhonePermission() => Promise<void>

isOpen()

isOpen() => Promise<{ isOpen: boolean; }>

Returns: Promise<{ isOpen: boolean; }>


addListener('onPlayed', ...)

addListener(eventName: 'onPlayed', listenerFunc: onPlayedListener) => Promise<PluginListenerHandle> & PluginListenerHandle
ParamType
eventName'onPlayed'
listenerFunconPlayedListener

Returns: Promise<PluginListenerHandle> & PluginListenerHandle


addListener('onOrientationChanged', ...)

addListener(eventName: 'onOrientationChanged', listenerFunc: onOrientationChangedListener) => Promise<PluginListenerHandle> & PluginListenerHandle
ParamType
eventName'onOrientationChanged'
listenerFunconOrientationChangedListener

Returns: Promise<PluginListenerHandle> & PluginListenerHandle


removeAllListeners()

removeAllListeners() => Promise<void>

Interfaces

ScanRegion

measuredByPercentage: 0 in pixel, 1 in percent

PropType
leftnumber
topnumber
rightnumber
bottomnumber
measuredByPercentagenumber
PluginListenerHandle
PropType
remove() => Promise<void>

Type Aliases

onPlayedListener

(result: { resolution: string; }): void

onOrientationChangedListener

(): void

Keywords

FAQs

Last updated on 03 Jan 2024

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc