Home

Awesome

capacitor-plugin-dynamsoft-camera-preview

A Capacitor plugin for camera preview using Dynamsoft Camera Enhancer.

Online Demo

Note: This package is not actively maintained. Please use capacitor-plugin-camera.

Supported Platforms

Versions

For Capacitor v5, use v2.x.

For Capacitor v4, use v1.x.

Install

npm install capacitor-plugin-dynamsoft-camera-preview
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.dynamsoft.capacitor.dce.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;
}

API

<docgen-index> </docgen-index> <docgen-api> <!--Update the source file JSDoc comments and rerun docgen to update the docs below-->

initialize()

initialize() => Promise<void>

getResolution()

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

Returns: <code>Promise<{ resolution: string; }></code>


setResolution(...)

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

getAllCameras()

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

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


getSelectedCamera()

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

Returns: <code>Promise<{ selectedCamera: string; }></code>


selectCamera(...)

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

setScanRegion(...)

setScanRegion(options: { region: ScanRegion; }) => Promise<void>
ParamType
options<code>{ region: <a href="#scanregion">ScanRegion</a>; }</code>

setZoom(...)

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

setFocus(...)

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

setDefaultUIElementURL(...)

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

Web Only

ParamType
url<code>string</code>

startCamera()

startCamera() => Promise<void>

stopCamera()

stopCamera() => Promise<void>

pauseCamera()

pauseCamera() => Promise<void>

resumeCamera()

resumeCamera() => Promise<void>

takeSnapshot(...)

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

take a snapshot as base64.

ParamType
options<code>{ quality?: number; }</code>

Returns: <code>Promise<{ base64: string; }></code>


takeSnapshot2()

takeSnapshot2() => Promise<{ frame: DCEFrame; }>

take a snapshot as <a href="#dceframe">DCEFrame</a>. Web Only

Returns: <code>Promise<{ frame: <a href="#dceframe">DCEFrame</a>; }></code>


takePhoto()

takePhoto() => Promise<{ base64: string; }>

Returns: <code>Promise<{ base64: string; }></code>


toggleTorch(...)

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

requestCameraPermission()

requestCameraPermission() => Promise<void>

isOpen()

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

Returns: <code>Promise<{ isOpen: boolean; }></code>


addListener('onPlayed', ...)

addListener(eventName: 'onPlayed', listenerFunc: onPlayedListener) => Promise<PluginListenerHandle> & PluginListenerHandle
ParamType
eventName<code>'onPlayed'</code>
listenerFunc<code><a href="#onplayedlistener">onPlayedListener</a></code>

Returns: <code>Promise<<a href="#pluginlistenerhandle">PluginListenerHandle</a>> & <a href="#pluginlistenerhandle">PluginListenerHandle</a></code>


removeAllListeners()

removeAllListeners() => Promise<void>

Interfaces

ScanRegion

measuredByPercentage: 0 in pixel, 1 in percent

PropType
left<code>number</code>
top<code>number</code>
right<code>number</code>
bottom<code>number</code>
measuredByPercentage<code>number</code>

DCEFrame

PropType
data<code><a href="#uint8array">Uint8Array</a></code>
region<code><a href="#region">Region</a></code>
sx<code>number</code>
sy<code>number</code>
width<code>number</code>
height<code>number</code>
stride<code>number</code>
colorMode<code>string</code>
pixelFormat<code>string</code>
timeSpent<code>number</code>
timeStamp<code>number</code>
isCropped<code>boolean</code>
toCanvas<code>() => any</code>
_sWidth<code>number</code>
_sHeight<code>number</code>
_bUseWebGL<code>boolean</code>

Uint8Array

A typed array of 8-bit unsigned integer values. The contents are initialized to 0. If the requested number of bytes could not be allocated an exception is raised.

PropTypeDescription
BYTES_PER_ELEMENT<code>number</code>The size in bytes of each element in the array.
buffer<code><a href="#arraybufferlike">ArrayBufferLike</a></code>The <a href="#arraybuffer">ArrayBuffer</a> instance referenced by the array.
byteLength<code>number</code>The length in bytes of the array.
byteOffset<code>number</code>The offset in bytes of the array.
length<code>number</code>The length of the array.
MethodSignatureDescription
copyWithin(target: number, start: number, end?: number | undefined) => thisReturns the this object after copying a section of the array identified by start and end to the same array starting at position target
every(predicate: (value: number, index: number, array: <a href="#uint8array">Uint8Array</a>) => unknown, thisArg?: any) => booleanDetermines whether all the members of an array satisfy the specified test.
fill(value: number, start?: number | undefined, end?: number | undefined) => thisReturns the this object after filling the section identified by start and end with value
filter(predicate: (value: number, index: number, array: <a href="#uint8array">Uint8Array</a>) => any, thisArg?: any) => <a href="#uint8array">Uint8Array</a>Returns the elements of an array that meet the condition specified in a callback function.
find(predicate: (value: number, index: number, obj: <a href="#uint8array">Uint8Array</a>) => boolean, thisArg?: any) => number | undefinedReturns the value of the first element in the array where predicate is true, and undefined otherwise.
findIndex(predicate: (value: number, index: number, obj: <a href="#uint8array">Uint8Array</a>) => boolean, thisArg?: any) => numberReturns the index of the first element in the array where predicate is true, and -1 otherwise.
forEach(callbackfn: (value: number, index: number, array: <a href="#uint8array">Uint8Array</a>) => void, thisArg?: any) => voidPerforms the specified action for each element in an array.
indexOf(searchElement: number, fromIndex?: number | undefined) => numberReturns the index of the first occurrence of a value in an array.
join(separator?: string | undefined) => stringAdds all the elements of an array separated by the specified separator string.
lastIndexOf(searchElement: number, fromIndex?: number | undefined) => numberReturns the index of the last occurrence of a value in an array.
map(callbackfn: (value: number, index: number, array: <a href="#uint8array">Uint8Array</a>) => number, thisArg?: any) => <a href="#uint8array">Uint8Array</a>Calls a defined callback function on each element of an array, and returns an array that contains the results.
reduce(callbackfn: (previousValue: number, currentValue: number, currentIndex: number, array: <a href="#uint8array">Uint8Array</a>) => number) => numberCalls the specified callback function for all the elements in an array. The return value of the callback function is the accumulated result, and is provided as an argument in the next call to the callback function.
reduce(callbackfn: (previousValue: number, currentValue: number, currentIndex: number, array: <a href="#uint8array">Uint8Array</a>) => number, initialValue: number) => number
reduce<U>(callbackfn: (previousValue: U, currentValue: number, currentIndex: number, array: <a href="#uint8array">Uint8Array</a>) => U, initialValue: U) => UCalls the specified callback function for all the elements in an array. The return value of the callback function is the accumulated result, and is provided as an argument in the next call to the callback function.
reduceRight(callbackfn: (previousValue: number, currentValue: number, currentIndex: number, array: <a href="#uint8array">Uint8Array</a>) => number) => numberCalls the specified callback function for all the elements in an array, in descending order. The return value of the callback function is the accumulated result, and is provided as an argument in the next call to the callback function.
reduceRight(callbackfn: (previousValue: number, currentValue: number, currentIndex: number, array: <a href="#uint8array">Uint8Array</a>) => number, initialValue: number) => number
reduceRight<U>(callbackfn: (previousValue: U, currentValue: number, currentIndex: number, array: <a href="#uint8array">Uint8Array</a>) => U, initialValue: U) => UCalls the specified callback function for all the elements in an array, in descending order. The return value of the callback function is the accumulated result, and is provided as an argument in the next call to the callback function.
reverse() => <a href="#uint8array">Uint8Array</a>Reverses the elements in an Array.
set(array: <a href="#arraylike">ArrayLike</a><number>, offset?: number | undefined) => voidSets a value or an array of values.
slice(start?: number | undefined, end?: number | undefined) => <a href="#uint8array">Uint8Array</a>Returns a section of an array.
some(predicate: (value: number, index: number, array: <a href="#uint8array">Uint8Array</a>) => unknown, thisArg?: any) => booleanDetermines whether the specified callback function returns true for any element of an array.
sort(compareFn?: ((a: number, b: number) => number) | undefined) => thisSorts an array.
subarray(begin?: number | undefined, end?: number | undefined) => <a href="#uint8array">Uint8Array</a>Gets a new <a href="#uint8array">Uint8Array</a> view of the <a href="#arraybuffer">ArrayBuffer</a> store for this array, referencing the elements at begin, inclusive, up to end, exclusive.
toLocaleString() => stringConverts a number to a string by using the current locale.
toString() => stringReturns a string representation of an array.
valueOf() => <a href="#uint8array">Uint8Array</a>Returns the primitive value of the specified object.

ArrayLike

PropType
length<code>number</code>

ArrayBufferTypes

Allowed <a href="#arraybuffer">ArrayBuffer</a> types for the buffer of an ArrayBufferView and related Typed Arrays.

PropType
ArrayBuffer<code><a href="#arraybuffer">ArrayBuffer</a></code>

ArrayBuffer

Represents a raw buffer of binary data, which is used to store data for the different typed arrays. ArrayBuffers cannot be read from or written to directly, but can be passed to a typed array or DataView Object to interpret the raw buffer as needed.

PropTypeDescription
byteLength<code>number</code>Read-only. The length of the <a href="#arraybuffer">ArrayBuffer</a> (in bytes).
MethodSignatureDescription
slice(begin: number, end?: number | undefined) => <a href="#arraybuffer">ArrayBuffer</a>Returns a section of an <a href="#arraybuffer">ArrayBuffer</a>.

Region

PropType
regionBottom<code>number</code>
regionRight<code>number</code>
regionLeft<code>number</code>
regionTop<code>number</code>
regionMeasuredByPercentage<code>number | boolean</code>

PluginListenerHandle

PropType
remove<code>() => Promise<void></code>

Type Aliases

ArrayBufferLike

<code>ArrayBufferTypes[keyof ArrayBufferTypes]</code>

onPlayedListener

<code>(result: { resolution: string; }): void</code>

</docgen-api>