# CameraEnhancer

The `CameraEnhancer` class provides camera-specific functionality including camera selection, focus control, zoom, and other enhanced features. The `CameraEnhancer` is also responsible for the basic UI of the camera view.

## Definition

*Assembly:* dynamsoft-capture-vision-react-native

```js
class CameraEnhancer extends ImageSourceAdapter
```

## Static Properties

| Property | Description |
| -------- | ----------- |
| [`instance`](#instance) | Returns the singleton instance of `CameraEnhancer`. |

### instance

```js
static CameraEnhancer get instance;
```

## Methods

| Method | Description |
| ------ | ----------- |
| [`close`](#close) | Closes the camera and releases the related resources. |
| [`destroy`](#destroy) | Destroys the camera enhancer instance and releases the related resources on the host side. |
| [`disableEnhancedFeatures`](#disableenhancedfeatures) | Disables the selected and activated enhanced features of the Camera Enhancer. |
| [`enableEnhancedFeatures`](#enableenhancedfeatures) | Activates the selected enhanced features provided by the Camera Enhancer library, including the auto-zoom and smart torch features. |
| [`getCameraPosition`](#getcameraposition) | Returns the current camera being used. |
| [`getFocusMode`](#getfocusmode) | Returns the current focus mode of the camera. |
| [`getScanRegion`](#getscanregion) | Returns the current scan region. |
| [`getZoomFactor`](#getzoomfactor) | Returns the current zoom factor of the camera. |
| [`open`](#open) | Opens the selected camera to begin the capture process. |
| [`selectCamera`](#selectcamera) | Selects the camera based on the specified camera position. |
| [`setFocus`](#setfocus) | Sets the focus point as well as the mode for the camera. |
| [`setResolution`](#setresolution) | Sets the resolution of the camera. |
| [`setScanRegion`](#setscanregion) | Sets the scan region of the camera and displays a bordered area on the UI. |
| [`setZoomFactor`](#setzoomfactor) | Sets the zoom factor of the camera. |
| [`turnOffTorch`](#turnofftorch) | Turns off the camera's flashlight (if available). |
| [`turnOnTorch`](#turnontorch) | Turns on the camera's flashlight (if available). |
| [`getInstance`](#getinstance) | Gets the singleton instance of `CameraEnhancer`. |
| [`requestCameraPermission`](#requestcamerapermission) | Request the camera permission. |

The following methods are inherited from superclass [`ImageSourceAdapter`](https://www.dynamsoft.com/capture-vision/docs/mobile/programming/react-native/api-reference/core/image-source-adapter.md)

| Method | Description |
| ------ | ----------- |
| [`addImageToBuffer`](https://www.dynamsoft.com/capture-vision/docs/mobile/programming/react-native/api-reference/core/image-source-adapter.md#addimagetobuffer) | Adds an image to the internal buffer. |
| [`clearBuffer`](https://www.dynamsoft.com/capture-vision/docs/mobile/programming/react-native/api-reference/core/image-source-adapter.md#clearbuffer) | Clears all images from the buffer, resetting the state for new image fetching. |
| [`getBufferOverflowProtectionMode`](https://www.dynamsoft.com/capture-vision/docs/mobile/programming/react-native/api-reference/core/image-source-adapter.md#getbufferoverflowprotectionmode) | Get the current mode for handling buffer overflow. |
| [`getColourChannelUsageType`](https://www.dynamsoft.com/capture-vision/docs/mobile/programming/react-native/api-reference/core/image-source-adapter.md#getcolourchannelusagetype) | Get the current usage type for color channels in images. |
| [`getImage`](https://www.dynamsoft.com/capture-vision/docs/mobile/programming/react-native/api-reference/core/image-source-adapter.md#getimage) | Get a buffered image. Implementing classes should return a Promise that resolves with an instance of `ImageData`. |
| [`getMaximumImageCount`](https://www.dynamsoft.com/capture-vision/docs/mobile/programming/react-native/api-reference/core/image-source-adapter.md#getmaximumimagecount) | Get the maximum number of images that can be buffered. |
| [`hasImage`](https://www.dynamsoft.com/capture-vision/docs/mobile/programming/react-native/api-reference/core/image-source-adapter.md#hasimage) | Checks if an image with the specified ID is present in the buffer. |
| [`setBufferOverflowProtectionMode`](https://www.dynamsoft.com/capture-vision/docs/mobile/programming/react-native/api-reference/core/image-source-adapter.md#setbufferoverflowprotectionmode) | Sets the behavior for handling new incoming images when the buffer is full. |
| [`setColourChannelUsageType`](https://www.dynamsoft.com/capture-vision/docs/mobile/programming/react-native/api-reference/core/image-source-adapter.md#setcolourchannelusagetype) | Sets the usage type for color channels in images. |
| [`setMaximumImageCount`](https://www.dynamsoft.com/capture-vision/docs/mobile/programming/react-native/api-reference/core/image-source-adapter.md#setmaximumimagecount) | Sets the maximum number of images that can be buffered at any time. |
| [`setNextImageToReturn`](https://www.dynamsoft.com/capture-vision/docs/mobile/programming/react-native/api-reference/core/image-source-adapter.md#setnextimagetoreturn) | Sets the processing priority of a specific image. This can affect the order in which images are returned by getImage. |
| [`startFetching`](https://www.dynamsoft.com/capture-vision/docs/mobile/programming/react-native/api-reference/core/image-source-adapter.md#startfetching) | Start fetching images from the source to the Video Buffer of `ImageSourceAdapter`. |
| [`stopFetching`](https://www.dynamsoft.com/capture-vision/docs/mobile/programming/react-native/api-reference/core/image-source-adapter.md#stopfetching) | Stop fetching images from the source to the Video Buffer of `ImageSourceAdapter`. |

### close

Closes the camera and releases the related resources. When the `CaptureVisionRouter` instance calls `stopCapturing`, please make sure to call this method as well to ensure that the resources are released properly.

```js
close()
```

### destroy

Destroys the camera enhancer instance and releases the related resources on the host side.

```js
destroy()
```

### disableEnhancedFeatures

Disables the selected and activated enhanced features of the Camera Enhancer.

```js
disableEnhancedFeatures(features: EnumEnhancedFeatures | number)
```

**Parameters**

`features`: An enum value or a combination of [`EnumEnhancedFeatures`](https://www.dynamsoft.com/camera-enhancer/docs/mobile/programming/react-native/api-reference/enum/enhanced-features-camera.md) indicating the features to be disabled.

### enableEnhancedFeatures

Activates the selected enhanced features (represented by [`EnumEnhancedFeatures`](https://www.dynamsoft.com/camera-enhancer/docs/mobile/programming/react-native/api-reference/enum/enhanced-features-camera.md)) provided by the Camera Enhancer library, including the auto-zoom and smart torch features.

```js
enableEnhancedFeatures(features: EnumEnhancedFeatures | number)
```

**Parameters**

`features`: An enum value or a combination of [`EnumEnhancedFeatures`](https://www.dynamsoft.com/camera-enhancer/docs/mobile/programming/react-native/api-reference/enum/enhanced-features-camera.md) indicating the features to be disabled.

### getCameraPosition

Returns the current camera being used, represented as a [`EnumCameraPosition`](https://www.dynamsoft.com/camera-enhancer/docs/mobile/programming/react-native/api-reference/enum/camera-position.md).

```js
getCameraPosition(): Promise<number>
```

**Returns**

A promise that resolves the current camera position, of type [`EnumCameraPosition`](https://www.dynamsoft.com/camera-enhancer/docs/mobile/programming/react-native/api-reference/enum/camera-position.md).

### getFocusMode

Returns the current focus mode of the camera, represented as a [`EnumFocusMode`](https://www.dynamsoft.com/camera-enhancer/docs/mobile/programming/react-native/api-reference/enum/focus-mode.md).

```js
getFocusMode(): Promise<number>
```

**Returns**

A promise that resolves the current focus mode, of type [`EnumFocusMode`](https://www.dynamsoft.com/camera-enhancer/docs/mobile/programming/react-native/api-reference/enum/focus-mode.md).

### getScanRegion

Returns the current scan region as a [`DSRect`](https://www.dynamsoft.com/capture-vision/docs/mobile/programming/react-native/api-reference/core/dsrect.md) object.

```js
getScanRegion(): Promise<undefined | null | DSRect>
```

**Returns**

A promise that resolves current scan region.

### getZoomFactor

Returns the current zoom factor of the camera.

```js
getZoomFactor(): Promise<number>
```

**Returns**

A promise that resolves current zoom factor.

### open

Opens the selected camera to begin the capture process.

```js
open()
```

### selectCamera

Selects the camera based on the specified [`EnumCameraPosition`](https://www.dynamsoft.com/camera-enhancer/docs/mobile/programming/react-native/api-reference/enum/camera-position.md).

```js
selectCamera(position: number)
```

**Parameters**

`position`: One of the [`EnumCameraPosition`](https://www.dynamsoft.com/camera-enhancer/docs/mobile/programming/react-native/api-reference/enum/camera-position.md).

**Remarks**

- **backUltraWide** & **backDualWideAuto**: iPhone only.

### setCameraView

Bind a CameraView instance with this CameraEnhancer instance.

```js
setCameraView(view: CameraView)
```

**Parameters**

`view`: A [`CameraView`](https://www.dynamsoft.com/camera-enhancer/docs/mobile/programming/react-native/api-reference/camera-view.md) element.

### setFocus

Sets the focus point as well as the mode (as a [`EnumFocusMode`](https://www.dynamsoft.com/camera-enhancer/docs/mobile/programming/react-native/api-reference/enum/focus-mode.md)) for the camera.

```js
setFocus(floatX: number, floatY: number, focusMode: number)
```

**Parameters**

`floatX`: The x of focus point of interest. The coordinate base of the point is "image".

`floatY`: The y of focus point of interest. The coordinate base of the point is "image".

`focusMode`: The subsequent focus mode.

### setResolution

Sets the resolution of the camera.

```js
setResolution(resolution: EnumResolution)
```

**Parameters**

`resolution`: One of the [`EnumResolution`](https://www.dynamsoft.com/camera-enhancer/docs/mobile/programming/react-native/api-reference/enum/resolution.md).

### setScanRegion

Sets the scan region of the camera and displays a bordered area on the UI to represent the scan region. To learn how to specify the scan region when using the Barcode Reader, please visit this [section of the foundational user guide](https://www.dynamsoft.com/barcode-reader/docs/mobile/programming/react-native/explore-features/ui-customization.md#specifying-a-scan-region).

```js
setScanRegion(region: undefined | null | DSRect)
```

**Parameters**

`region`: Specifies the scan region. If null or undefined, cancel the scan region.

**See also**

- [`DSRect`](https://www.dynamsoft.com/capture-vision/docs/mobile/programming/react-native/api-reference/core/dsrect.md).

> [!Note]
> The valid range for left, right, top, and bottom is [0.0, 1.0] when measuredInPercentage is true.

### setZoomFactor

Sets the zoom factor of the camera.

```js
setZoomFactor(factor: number)
```

**Parameters**

`factor`: The zoom factor.

### turnOffTorch

Turns off the camera's flashlight (if available).

```js
turnOffTorch()
```

### turnOnTorch

Turns on the camera's flashlight (if available).

```js
turnOnTorch()
```

### getInstance

Get the singleton instance of `CameraEnhancer`.

```js
static getInstance(): CameraEnhancer
```

### requestCameraPermission

Request the camera permission.

```js
static async requestCameraPermission()
```
