Cordova plugin that allows camera interaction from Javascript and HTML, using CameraX api, only on Android.
This plugin is under constant development. It is recommended to use master to always have the latest fixes and features.
PR's are greatly appreciated
- Start/Stop a camera preview.
- Get/set zoom ratio.
- Get/set flash mode.
- Take a picture and save into file
- Start/Stop video recording
- Tap to focus
- Pinch to zoom
Use any one of the installation methods listed below depending on which framework you use.
To install the master version with latest fixes and features
cordova plugin add https://github.com/Qarma-inspect/cordova-plugin-camerax.git
Starts the camera preview instance.
Options: All options stated are optional and will default to values here tapToFocus and pinchToZoom are set by default. Flags to control those features will be added later.
x
- Defaults to 0y
- Defaults to 0width
- Defaults to window.screen.widthheight
- Defaults to window.screen.height
let options = {
x: 0,
y: 0,
width: window.screen.width,
height: window.screen.height
};
CameraXPlugin.startCameraX(options);
Stops the camera preview instance.
CameraXPlugin.stopCameraX();
Take the picture. The argument quality
defaults to 85
and specifies the quality/compression value: 0=max compression
, 100=max quality
.
Currently resolution is set as 1200x1600 by default, if the phone doesnot support this resolution, CameraX will choose the closest resolution that is bigger than 1200x1600 and has ratio 3x4.
CameraXPlugin.takePictureWithCameraX({fileName: 'photo-1', quality: 90, rotation: ''}, function([imageFilePath, thumbnailFilePath]]){}, function(error) {});
Return the maximum zoom ratio, so you can use to set your zoom steps
CameraXPlugin.getMaxZoomCameraX(function(zoomRatio){}, function(error) {});
Set the zoom level for the camera device currently started. zoomMultipler option accepts an integer. Zoom level is initially at 1
CameraXPlugin.setZoomCameraX(zoomRatio, function(){}, function(error) {});
Get the flash mode for the camera device currently started. Returns a string representing the current flash mode.See FLASH_MODE
for possible values that can be returned
CameraXPlugin.getFlashModeCameraX(function(currentFlashMode){
console.log(currentFlashMode);
});
Set the flash mode. See FLASH_MODE
for details about the possible values for flashMode.
CameraXPlugin.setFlashMode(CameraPreview.FLASH_MODE.ON);
Starts recording.
Options:
fileName
- should be uniquedurationLimit
- in seconds
let options = {
fileName: 'video-1',
durationLimit: 12
};
CameraXPlugin.startRecordingCameraX(options);
Stop recording and save the recording into file
CameraXPlugin.stopRecordVideo(function(videoPath) {}, function(error) {});