Scandit.Camera

new Camera(options?: object)

Creates a new instance of the camera

Parameters:
Name Type Attributes Description
options object <optional>

Camera configuration

Properties
Name Type Attributes Default Description
camera string <optional>
back

Which camera to use. Possible values: front, back

maxResolution object <optional>

Resolution of the output image. Default is the maximum resolution supported by the device camera.

Properties
Name Type Attributes Description
width integer <optional>

Width of the output image in pixels.

height integer <optional>

Height of the output image in pixels.

quality integer <optional>
100

Picture quality. Possible values: 1-100.

Examples
  • JavaScript
  • ES6
var camera = new Scandit.Camera({
  camera: 'front',
  maxResolution: {
    width: 1080,
    height: 1920
  },
  quality: 80
});
const camera = new Scandit.Camera({
  camera: 'front',
  maxResolution: {
    width: 1080,
    height: 1920
  },
  quality: 80
});

Methods

capture(): Promise

Starts the camera

Returns:
Promise

Promise which is resolved to the local file url with mime type image/jpg.

Can return error with codes:

Examples
  • JavaScript
  • ES6
var camera = new Camera();
camera.capture().then(function(imagePath) {
  // do something with the image here
  console.log('Image just captured and saved at path: ' + imagePath);
}).catch(console.warn);
const camera = new Camera();
camera.capture().then(imagePath => {
  // do something with the image here
  console.log(`Image just captured and saved at path: ${imagePath}`);
}).catch(console.warn);

close()

Closes the camera

Examples
  • JavaScript
  • ES6
var camera = new Camera();
camera.capture().then(handleImage);

// assuming that `shouldCloseCamera` is set based on some conditions that tell if the camera should be closed
// before the user finishes capturing the image
if (shouldCloseCamera) { camera.close(); }
const camera = new Camera();
camera.capture().then(handleImage);

// assuming that `shouldCloseCamera` is set based on some conditions that tell if the camera should be closed
// before the user finishes capturing the image
if (shouldCloseCamera) { camera.close(); }