Camera Controls

To use the camera controls, we can use HMSCameraControls class to access it's functionality.

Minimum Requirements

  • SDK version 1.5.0 or higher

Capture at the highest resolution offered by the camera

Takes the highest quality picture from the local video stream in jpg format irrespective of publisher's resolution. It contains withFlash parameter which if true turns on the flash while capturing image. Default value of withFlash parameter is false.

🔑 Note: captureImageAtMaxSupportedResolution method only works if camera is turned ON

//To capture image with `withFlash` as true //`filePath` can return either the filePath string or an HMSException object in case of error dynamic filePath = await HMSCameraControls.captureImageAtMaxSupportedResolution(withFlash: true); if(filePath is HMSException) { //Log the error here //Handle the error accordingly } else{ //Create image file and use it accordingly File imageFile = File(filePath); // We can display the image using `Image.file` widget in our applications // Image.file(imageFile) }

Flash

Check if flash feature is available

Checks if the current facing camera has a flash device.

dynamic isFlashSupported = await HMSCameraControls.isFlashSupported(); if(isFlashSupported is HMSException) { //Log the error here //Handle the error accordingly } else{ //Check here whether flash is supported or not //isFlashSupported will be a boolean }

Toggle flash

This method is used to toggle flash, i.e. if its ON it turns it OFF and vice-versa.

HMSCameraControls.toggleFlash();

🔑 Note: If camera is toggled while flash is ON, then flash turns OFF.

Zoom Controls

Check if zoom feature is available

To check if the current facing camera supports zoom feature.

var isZoomSupported = await HMSCameraControls.isZoomSupported();

Set Zoom Level

To set zoom for camera, we can use setZoom method. For android zoomValue should be between 1 and max zoom level. For iOS zoomValue must be in the range supported by camera.

// To zoom in the camera by 2x HMSCameraControls.setZoom(zoomValue: 2);

Reset Zoom Level

To reset the zoom level to 1x, we can use resetZoom method:

// To reset the zoom level back to 1x HMSCameraControls.resetZoom();

Get max zoom level (Android Only)

To get the maximum zoom level supported by the camera, we can use getMaxZoom method:

var maxZoom = await HMSCameraControls.getMaxZoom();

Get min zoom level (Android Only)

To get the minimum zoom level supported by the camera, we can use getMinZoom method:

var minZoom = await HMSCameraControls.getMinZoom();

Have a suggestion? Recommend changes ->

Was this helpful?

1234