capturePic

Camera

Launches the native camera app to capture a picture. The captured picture can be written to the photos gallery or to a specific location in the app.

$m.capturePic(function(response) {

        if(response.code){

// set the src of the image to the captured picture

                juci.controls.get("captured-pic").value(response.result.path);

        } else{

// show error as toast message.

                $m.toast(response.error.message);

        }

});

Syntax

        $m.capturePic(fp_callback)

        $m.capturePic(options, fp_callback)

Parameters

fp_callback

function (required)

Function to execute when the user has captured a picture in the native camera app. The function receives a response object with the following properties,

  1. code - {Number}. The value can be 0 or 1. 1 indicates that a picture has been captured and written to the specified filePath or photos gallery successfully. 0 indicates a failure.

  1. result - {Object}. Available when the code is 1. The result object contains,
  1. path - {String}. Path of the file to which the captured picture is written.
  2. data - {String}. Base64 encoded string of the picture data. This is available only when the options.readData is set to true.

  1. error - {Object}. Available when the code is 0. The error object contains,
  1. message - {String}. A short description of the error.
  2. description - {String}. A detailed description of the error.

options

object (optional)  

Optional parameters for the capture picture operation. The options object overrides the default options set using the camSetup method. The object can contain the following properties,

  1. allowEdit- {Optional. Boolean}. If true, user is allowed to edit the picture after capturing it in the native camera app. Default value is false. Supported in iOS only.

  1. filePath - {Optional. String/File}. Path to store the captured picture. The path, if provided as string is considered relative to the pack folder. Default value is path of photos gallery. Use $m.file to get a mowbly File object, which provides advanced file options.

  1. type - {Optional. Integer}. Format in which the captured picture is stored . Default value is $m.CAM_JPG. Supported values are,
  1. $m.CAM_JPG
  2. $m.CAM_PNG

  1. quality - {Optional. Number}. Quality of the captured picture. Default value is $m.CAM_QUALITY_MED. This quality value denotes the compression rate of the captured picture. Higher the quality higher the time taken to process the picture and the memory usage. Supported values are:
  1. $m.CAM_QUALITY_LOW
  2. $m.CAM_QUALITY_MED
  3. $m.CAM_QUALITY_HIGH

  1. readData - {Optional. Boolean}. Flag that denotes if the picture data should be returned to the fp_callback function. The picture data will be a base64 encoded string. It is recommended to use the path returned to the fp_callback function to render the picture in the page or to upload the picture to server (Refer postMultipart method for details.). Reading picture data would increase the memory usage of the app, hence this property should be used only when absolutely needed. Default value is false.

  1. width - {Optional. Integer}. Width of the captured picture in pixels. Default value is 320. The width is applied before the captured picture is written to the filePath or photos gallery.

  1. height - {Optional. Integer}. Height of the captured picture in pixels. Default value is 480. The height is applied before the captured picture is written to the filePath or photos gallery.

Remarks

The options parameter can be set globally in the page using the camSetup method, which will be used by all the following capturePic method calls. The photos gallery is the Camera roll album and can be accessed using the native Photos/Gallery app. 

The native Camera app returns the picture as per its settings and it is usually the highest resolution possible. Based on the app needs, resize the image by mentioning the options.width and options.height dimensions. Combination of these dimensions and quality parameter decide the final crispness of the picture.