takePicture Method

Use this command to take a picture with your device's camera.

intel.xdk.camera.takePicture(quality, saveToLibrary, pictureType);

Description:

When this command is called, the native camera application for the device will open and allow the user to take a picture. Once the photo has been taken, the camera application will return control to the application. At that point, any events associated with this command will be fired.

Available Platforms:

Parameters:

  • quality: The quality parameter reflects the percentage of image compression done to the image captured by the camera. This parameter must be a value between 1 and 100. The default value is 70.
  • saveToLibrary: This parameter controls whether the photo is saved directly to the device's image library or not. It should be a boolean value (i.e. true or false). The default value is true.
  • pictureType: The parameter controls the file type the photo can be saved as. The valid string values are "jpg" and "png" respectively. The default value is "jpg".

Events:

  • intel.xdk.camera.picture.add: This event is fired once the takePicture method has completed. It will return parameters indicating whether it was successful or not, as well as the filename of the newly captured photo.
  • intel.xdk.camera.picture.busy: This event will be fired if the camera.takePicture method is called while another process is blocking access to the camera.
  • intel.xdk.camera.picture.cancel: This event will be fired if the native camera functionality is cancelled without taking a photo.

Example:


document.addEventListener("intel.xdk.camera.picture.add",onSuccess); 
document.addEventListener("intel.xdk.camera.picture.busy",onSuccess); 
document.addEventListener("intel.xdk.camera.picture.cancel",onSuccess); 

function capturePhoto() {
  intel.xdk.camera.takePicture(50,false,"jpg");
}

function onSuccess(evt) {

  if (evt.success == true)
  {
    // create image 
    var image = document.createElement('img');
    image.src=intel.xdk.camera.getPictureURL(evt.filename);
    image.id=evt.filename;
    document.body.appendChild(image);
  }
  else
  {
    if (evt.message != undefined)
    {
        alert(evt.message);
    }
    else
    {
        alert("error capturing picture");
    }
  }
}
            
Пожалуйста, обратитесь к странице Уведомление об оптимизации для более подробной информации относительно производительности и оптимизации в программных продуктах компании Intel.