/cordova-plugin-camera-preview

Cordova plugin that allow camera interaction from HTML code

Primary LanguageJavaApache License 2.0Apache-2.0

Cordova CameraPreview Plugin

Cordova plugin that allows camera interaction from HTML code.
Show camera preview popup on top of the HTML.

Features:

  • Start a camera preview from HTML code.
  • Drag the preview box.
  • Set camera color effect.
  • Send the preview box to back of the HTML content.
  • Set a custom position for the camera preview box.
  • Set a custom size for the preview box.
  • Set a custom alpha for the preview box.
  • Maintain HTML interactivity.

Installation:

cordova plugin add cordova-plugin-camera-preview
ionic plugin add cordova-plugin-camera-preview

Phonegap Build:

<gap:plugin name="cordova-plugin-camera-preview" />

Methods:

startCamera()
Starts the camera preview instance.

When setting the toBack to TRUE, remember to add the style bellow on your app's HTML or body element:

html, body{
  background-color: transparent;
}

Javascript:

/* All options stated are optional and will default to values here */
CameraPreview.startCamera({x: 0, y: 0, width: window.device.width, height: window.device.height, camera: "front", tapPhoto: true, previewDrag: false, toBack: false});

stopCamera()
Stops the camera preview instance.

CameraPreview.stopCamera();

takePicture(size)
Take the picture, the parameter size is optional

CameraPreview.takePicture({maxWidth:640, maxHeight:640});

setOnPictureTakenHandler(callback)
Register a callback function that receives the image captured from the preview box.

CameraPreview.setOnPictureTakenHandler(function (picture) {
  document.getElementById('picture').src = picture; // base64 picture;
});

switchCamera()
Switch from the rear camera and front camera, if available.

CameraPreview.switchCamera();

show()
Show the camera preview box.

CameraPreview.show();

hide()
Hide the camera preview box.

CameraPreview.hide();

IOS Quirks:
It is not possible to use your computers webcam during testing in the simulator, you must device test.

Sample:
Cordova: cordova-plugin-camera-preview-sample-app for a complete working Cordova example for Android and iOS platforms.

Ionic: cordova-plugin-camera-preview-ionic-sample-app for a complete working Ionic example for Android and iOS platforms.

Android Screenshots: