Please note, this is a STATIC archive of website developer.mozilla.org from November 2016, cach3.com does not collect or store any user information, there is no "phishing" involved.

CameraControl.takePicture()

This API is available on Firefox OS for privileged or certified applications only.

Summary

Captures a still image from the camera and passes it as a Blob to a success callback handler, which can manipulate the image as you wish (for example, by manipulating its pixel data or storing it).

If the camera supports doing so, you may call this method while the camera is already recording video.

Note: Using this function will stop the preview stream, which must be specifically resumed by calling CameraControl.resumePreview().

Syntax

CameraControl.takePicture(options, onsuccess[, onerror]);

Parameters

options
An object specifying options for the photo capture operation; see Options below.
onsuccess
A callback function to be invoked once the image has been captured. The function receives one parameter: a Blob containing a JPEG formatted image.
onerror Optional
An optional callback function that's invoked if an error occurs; it receives one parameter: an error string.

Options

The options object passed to this method has the following properties:

 
dateTime Optional
The time at which the image was captured, in seconds since the beginning of January 1, 1970 UTC. This date will be add to the EXIF header as the recording time of the photo.
fileFormat Optional
A string indicated the file format of the picture. This object must match one of the supported file format described in the CameraCapabilities object's fileFormats property.
pictureSize Optional
An object with two properties—width and height—indicating the size of image to capture. This object must match one of the supported image sizes described in the CameraCapabilities object's pictureSizes property. You may specify null to use the default size.
position Optional
An optional object that contains metadata that can be added to the captured image; this information describes geolocation data about where and when the photo was taken, as described in Position.
rotation Optional
The number of degrees clockwise to rotate the image upon capture.

Position

The position object, specified as a property of the options object, provides optional additional GPS metadata that can be attached to the captured image.

timestamp Optional
The time at which the image was captured, in seconds since the beginning of January 1, 1970 UTC.
altitude Optional
The altitude at which the image was captured, in meters above sea level.
latitude Optional
The latitude at which the image was captured, in degrees.
longitude Optional
The longitude at which the image was captured, in degrees.

Example

var storage = navigator.getDeviceStorage('pictures');
var cameraOptions = {
  camera: navigator.mozCameras.getListOfCameras()[0]
};
var pictureOptions = {
  rotation: 90,
  pictureSize: null,
  fileFormat: null
}

function onPictureTaken( blob ) {
  storage.addNamed(blob, 'myImage.jpg');
}

function onAccessCamera( camera ) {
  pictureOptions.pictureSize = camera.capabilities.pictureSizes[0];
  pictureOptions.fileformat  = camera.capabilities.fileFormats[0];

  camera.takePicture(pictureOptions, onPictureTaken);
};

navigator.mozCameras.getCamera(cameraOptions, onAccessCamera)

Specification

Not part of any specification; however, this API should be removed when the WebRTC Capture and Stream API has been implemented.

See also

Document Tags and Contributors

 Contributors to this page: chrisdavidmills, teoli, ajaybhat, kscarfone, Sheppy, Jeremie
 Last updated by: chrisdavidmills,