Warning Older Docs! - You are viewing documentation for a previous released version of RhoMobile Suite.

Camera

The Camera API provides access to your device’s Camera(s)

Use this API to give users the ability to take a photo via one of the device’s cameras and return it to the application. Photos can either be stored on the device and optionally transfered to an online server using the Network API or can be returned as a DataURI object for storing or display.

Enabling the API

In order to use this API you must include the following extension in your build.yml

extensions: ["mediacapture"]

JavaScript Usage

Be sure to review the JavaScript API Usage guide for important information about using this API in JavaScript

Ruby Usage

Be sure to review the Ruby API Usage guide for important information about using this API in Ruby

Methods

choosePicture(HASH propertyMap, CallBackHandler callback)

Choose a picture from the album.

Parameters

  • propertyMap : HASH Optional

    Provide a set of properties to configure an image, for example to specify the image size or color mode.

    Valid `properties` for this parameter are the properties avaliable to this API module. Check the property section

    Not providing properties to this function will use the Camera’s default properties, or those previously set on the Camera instance.

  • callback : CallBackHandler Mandatory

Async Callback Returning Parameters: HASH

    • status : STRING

      Whether or not the image was successfully chosen from the gallery. The returned string will be one of ‘ok’, ‘cancel’ or ‘error’.

    • imageUri : STRING

      The URI to the chosen image.

    • imageHeight : INTEGER

      The height of the image.

    • imageWidth : INTEGER

      The width of the image.

    • imageFormat : STRING

      The format of the image, either ‘png’ or ‘jpg’.

    • message : STRING

      If the returned status is ‘error’ then this field will contain more information on the error.

    • image_uri : STRING

      It is recommended to use imageUri in preference to this parameter.

    • image_height : INTEGER

      It is recommended to use imageHeight in preference to this parameter.

    • image_width : INTEGER

      It is recommended to use imageWidth in preference to this parameter.

    • image_format : STRING

      It is recommended to use imageFormat in preference to this parameter.

Synchronous Return:

  • Void : this method also supports async callbacks - check the Callback tab for callback return parameters.

Method Access:

  • Class Method: This method can only be accessed via the API class object.
    • Javascript: Rho.Camera.choosePicture(HASH propertyMap, CallBackHandler callback)
    • Ruby: Rho::Camera.choosePicture(HASH propertyMap, CallBackHandler callback)

getAllProperties(CallBackHandler callback)

This method will return all of object/value pairs for the propertyNames of the API class.

Parameters

  • callback : CallBackHandler Optional

Async Callback Returning Parameters: HASH

    • : STRING

Synchronous Return:

  • HASH :

    Map of all available properties

    : this method also supports async callbacks - check the Callback tab for callback return parameters.
    • : STRING

Method Access:

  • Instance Method: This method can be accessed via an instance object of this class:
    • myObject.getAllProperties(CallBackHandler callback)
  • Default Instance: This method can be accessed via the default instance object of this class.
    • Javascript: Rho.Camera.getAllProperties(CallBackHandler callback)
    • Ruby: Rho::Camera.getAllProperties(CallBackHandler callback)

getCameraByType(STRING cameraType, CallBackHandler callback)

Returns the camera of requested type if that camera exist – else return nil.

Parameters

  • cameraType : STRING

    CameraType: main or front.

  • callback : CallBackHandler Optional

Async Callback Returning Parameters: SELF_INSTANCE

    Synchronous Return:

    • SELF_INSTANCE :

      Camera with requested type or nil if not requested type does not exist.

      : this method also supports async callbacks - check the Callback tab for callback return parameters.

    Method Access:

    • Class Method: This method can only be accessed via the API class object.
      • Javascript: Rho.Camera.getCameraByType(STRING cameraType, CallBackHandler callback)
      • Ruby: Rho::Camera.getCameraByType(STRING cameraType, CallBackHandler callback)

    getDefault()

    This method will return an object that represents the default instance of the API Class. For example Camera.getDefault will return a Camera object that represents the default camera.

    Synchronous Return:

    • SELF_INSTANCE :

      Default object of Module.

    Method Access:

    • Class Method: This method can only be accessed via the API class object.
      • Javascript: Rho.Camera.getDefault()
      • Ruby: Rho::Camera.getDefault()

    getProperties(ARRAY arrayofNames, CallBackHandler callback)

    This method will return a set of object/value pairs for the list of the propertyName that is passed in. The propertyNames must be a valid property of the API class.

    Parameters

    • arrayofNames : ARRAY

      List of properties I want to know about

      • Object : STRING

    • callback : CallBackHandler Optional

    Async Callback Returning Parameters: HASH

      • : STRING

    Synchronous Return:

    • HASH :

      Map of properties I want to know about

      : this method also supports async callbacks - check the Callback tab for callback return parameters.
      • : STRING

    Method Access:

    • Instance Method: This method can be accessed via an instance object of this class:
      • myObject.getProperties(ARRAY arrayofNames, CallBackHandler callback)
    • Default Instance: This method can be accessed via the default instance object of this class.
      • Javascript: Rho.Camera.getProperties(ARRAY arrayofNames, CallBackHandler callback)
      • Ruby: Rho::Camera.getProperties(ARRAY arrayofNames, CallBackHandler callback)

    getProperty(STRING propertyName, CallBackHandler callback)

    This method will return the value of the propertyName that is passed in. The propertyName must be a valid property of the API class.

    Parameters

    • propertyName : STRING

      The property to return info about.

    • callback : CallBackHandler Optional

    Async Callback Returning Parameters: STRING

      Synchronous Return:

      • STRING :

        The property to return info about.

        : this method also supports async callbacks - check the Callback tab for callback return parameters.

      Method Access:

      • Instance Method: This method can be accessed via an instance object of this class:
        • myObject.getProperty(STRING propertyName, CallBackHandler callback)
      • Default Instance: This method can be accessed via the default instance object of this class.
        • Javascript: Rho.Camera.getProperty(STRING propertyName, CallBackHandler callback)
        • Ruby: Rho::Camera.getProperty(STRING propertyName, CallBackHandler callback)

      saveImageToDeviceGallery(STRING pathToImage)

      Replaces: save_image_to_device_gallery

      Save an image to the device gallery.

      Parameters

      • pathToImage : STRING

        The real path to the image that is to be saved in the device gallery. You need to use the RhoApplication method get_blob_path to have the real path, such as Rho::RhoApplication::get_blob_path(img.image_uri).

      Synchronous Return:

      • Void

      Method Access:

      • Class Method: This method can only be accessed via the API class object.
        • Javascript: Rho.Camera.saveImageToDeviceGallery(STRING pathToImage)
        • Ruby: Rho::Camera.saveImageToDeviceGallery(STRING pathToImage)

      setDefault(SELF_INSTANCE: Rho::Camera defaultInstance)

      This method allows you to set the attributes of the default object instance by passing in an object of the same class.

      Parameters

      • defaultInstance : SELF_INSTANCE: Rho::Camera

        An instance object that is of the same class.

      Synchronous Return:

      • Void

      Method Access:

      • Class Method: This method can only be accessed via the API class object.
        • Javascript: Rho.Camera.setDefault(SELF_INSTANCE: Rho::Camera defaultInstance)
        • Ruby: Rho::Camera.setDefault(SELF_INSTANCE: Rho::Camera defaultInstance)

      setProperties(HASH propertyMap)

      This method will set the values of a list of properties for the API class. The propertyName must be a valid property for the class and must also not be read only.

      Parameters

      • propertyMap : HASH

        Map of properties I want to set

        • Object : STRING

      Synchronous Return:

      • Void

      Method Access:

      • Instance Method: This method can be accessed via an instance object of this class:
        • myObject.setProperties(HASH propertyMap)
      • Default Instance: This method can be accessed via the default instance object of this class.
        • Javascript: Rho.Camera.setProperties(HASH propertyMap)
        • Ruby: Rho::Camera.setProperties(HASH propertyMap)

      setProperty(STRING propertyName, STRING propertyValue)

      This method will set the value of a property for the API class. The propertyName must be a valid property for the class and must also not be read only.

      Parameters

      • propertyName : STRING

        The one property name that I want to set

      • propertyValue : STRING

        The one property value that I want to set

      Synchronous Return:

      • Void

      Method Access:

      • Instance Method: This method can be accessed via an instance object of this class:
        • myObject.setProperty(STRING propertyName, STRING propertyValue)
      • Default Instance: This method can be accessed via the default instance object of this class.
        • Javascript: Rho.Camera.setProperty(STRING propertyName, STRING propertyValue)
        • Ruby: Rho::Camera.setProperty(STRING propertyName, STRING propertyValue)

      takePicture(HASH propertyMap, CallBackHandler callback)

      Start the camera application to take a picture. The user can capture the displayed image either by interacting with the resident camera app or pressing the trigger or enter key, depending on the device in use.

      Parameters

      • propertyMap : HASH Optional

        Provide a set of properties to configure the camera, for example to specify the flashMode or compressionFormat.

        Valid `properties` for this parameter are the properties avaliable to this API module. Check the property section

        Not providing properties to this function will use the Camera’s default properties, or those previously set on the Camera instance.

      • callback : CallBackHandler Mandatory

      Async Callback Returning Parameters: HASH

        • status : STRING

          Whether or not the image was successfully captured. The returned string will be one of ‘ok’, ‘cancel’ or ‘error’.

        • imageUri : STRING

          If the specified ‘outputFormat’ was ‘image’ then this field is the URI to the taken image stored on the device, this image will have an auto-generated name. If the specified ‘outputFormat’ was ‘dataUri’ then this field will be the image encoded as a Data URI.

        • imageHeight : INTEGER

          The actual height of the image that was captured, this may differ from the requested height as the Camera will only support a finite resolutions.

        • imageWidth : INTEGER

          The actual width of the image that was captured, this may differ from the requested width as the Camera will only support a finite resolutions.

        • imageFormat : STRING

          The format in which the image was captured, either ‘png’ or ‘jpg’.

        • message : STRING

          If the returned status is ‘error’ then this field will contain more information on the error.

        • image_uri : STRING

          It is recommended to use imageUri in preference to this parameter.

        • image_height : INTEGER

          It is recommended to use imageHeight in preference to this parameter.

        • image_width : INTEGER

          It is recommended to use imageWidth in preference to this parameter.

        • image_format : STRING

          It is recommended to use imageFormat in preference to this parameter.

      Synchronous Return:

      • Void : this method also supports async callbacks - check the Callback tab for callback return parameters.

      Method Access:

      • Instance Method: This method can be accessed via an instance object of this class:
        • myObject.takePicture(HASH propertyMap, CallBackHandler callback)
      • Default Instance: This method can be accessed via the default instance object of this class.
        • Javascript: Rho.Camera.takePicture(HASH propertyMap, CallBackHandler callback)
        • Ruby: Rho::Camera.takePicture(HASH propertyMap, CallBackHandler callback)

      Properties

      cameraType : STRING Read Only

      Replaces:camera_type

      Camera type: back or front.

      Default: main

      Possible Values (STRING):

      Constant: Rho.Camera.CAMERA_TYPE_BACK (For Ruby use "::" instead of ".")
      String: back

      Back camera.

      Constant: Rho.Camera.CAMERA_TYPE_FRONT (For Ruby use "::" instead of ".")
      String: front

      Front camera.

      Property Access:

      • Instance: This property can be accessed via an instance object of this class:
        • myObject.cameraType
      • Default Instance: This property can be accessed via the default instance object of this class.
        • Javascript: Rho.Camera.cameraType
        • Ruby: Rho::Camera.cameraType

      captureSound : STRING 4.0.0

      Path to a sound file resident on the device which will be played when the image is captured.

      Property Access:

      • Instance: This property can be accessed via an instance object of this class:
        • myObject.captureSound
      • Default Instance: This property can be accessed via the default instance object of this class.
        • Javascript: Rho.Camera.captureSound
        • Ruby: Rho::Camera.captureSound

      colorModel : STRING 2.0.0

      Replaces:color_model

      Where supported by the hardware this property can be used to select whether to capture a color or a grayscale image.

      Default: rgb

      Possible Values (STRING):

      Constant: Rho.Camera.COLOR_MODEL_RGB (For Ruby use "::" instead of ".")
      String: rgb

      A colour image is captured.

      Constant: Rho.Camera.COLOR_MODEL_GRAYSCALE (For Ruby use "::" instead of ".")
      String: grayscale

      A grayscale image is captured.

      Property Access:

      • Instance: This property can be accessed via an instance object of this class:
        • myObject.colorModel
      • Default Instance: This property can be accessed via the default instance object of this class.
        • Javascript: Rho.Camera.colorModel
        • Ruby: Rho::Camera.colorModel

      compressionFormat : STRING 4.0.0

      Replaces:format

      The format of the captured image in subsequent calls to takePicture(). If you do not define this property when you use choose_picture with iOS, the type of image in Gallery will be recognized, and the same format will be used for saving the image to applications data.

      Default: jpg

      Possible Values (STRING):

      Constant: Rho.Camera.COMPRESSION_FORMAT_JPG (For Ruby use "::" instead of ".")
      String: jpg

      JPG compression.

      Constant: Rho.Camera.COMPRESSION_FORMAT_PNG (For Ruby use "::" instead of ".")
      String: png

      PNG compression.

      Property Access:

      • Instance: This property can be accessed via an instance object of this class:
        • myObject.compressionFormat
      • Default Instance: This property can be accessed via the default instance object of this class.
        • Javascript: Rho.Camera.compressionFormat
        • Ruby: Rho::Camera.compressionFormat

      desiredHeight : INTEGER 2.0.0

      Replaces:desired_height

      Camera hardware is limited to taking photos in a finite number of resolutions, eg 2048x1536, 640x480 etc. Specifying a desiredHeight will request to take the photo with the specified height but if it is not supported by the hardware then the closest match will be selected. The callback received when a photo is taken contains the actual resolution of the captured photo.

      Property Access:

      • Instance: This property can be accessed via an instance object of this class:
        • myObject.desiredHeight
      • Default Instance: This property can be accessed via the default instance object of this class.
        • Javascript: Rho.Camera.desiredHeight
        • Ruby: Rho::Camera.desiredHeight

      desiredWidth : INTEGER 2.0.0

      Replaces:desired_width

      Camera hardware is limited to taking photos in a finite number of resolutions, eg 2048x1536, 640x480 etc. Specifying a desiredWidth will request to take the photo with the specified width but if it is not supported by the hardware then the closest match will be selected. The callback received when a photo is taken contains the actual resolution of the captured photo.

      Property Access:

      • Instance: This property can be accessed via an instance object of this class:
        • myObject.desiredWidth
      • Default Instance: This property can be accessed via the default instance object of this class.
        • Javascript: Rho.Camera.desiredWidth
        • Ruby: Rho::Camera.desiredWidth

      enableEditing : BOOLEAN 2.0.0

      Replaces:enable_editing

      Enables post photo capture image customizing; image will captured reduced to screen size (not full size).

      Default: true

      Property Access:

      • Instance: This property can be accessed via an instance object of this class:
        • myObject.enableEditing
      • Default Instance: This property can be accessed via the default instance object of this class.
        • Javascript: Rho.Camera.enableEditing
        • Ruby: Rho::Camera.enableEditing

      fileName : STRING 4.0.0

      The path without filename extension to store captured image in subsequent calls to takePicture(). The filename extension will be added automatically according to compressionFormat property value.

      Property Access:

      • Instance: This property can be accessed via an instance object of this class:
        • myObject.fileName
      • Default Instance: This property can be accessed via the default instance object of this class.
        • Javascript: Rho.Camera.fileName
        • Ruby: Rho::Camera.fileName

      flashMode : STRING 2.0.0

      Replaces:flash_mode

      Specifies the flash behavior when taking a picture.

      Possible Values (STRING):

      Constant: Rho.Camera.FLASH_ON (For Ruby use "::" instead of ".")
      String: on

      Flash will be used.

      Constant: Rho.Camera.FLASH_OFF (For Ruby use "::" instead of ".")
      String: off

      Flash will not be used.

      Constant: Rho.Camera.FLASH_AUTO (For Ruby use "::" instead of ".")
      String: auto

      Flash will be used if lighting conditions deem it necessary.

      Constant: Rho.Camera.FLASH_RED_EYE (For Ruby use "::" instead of ".")
      String: redEye

      Flash with red eye reduction is used.

      Constant: Rho.Camera.FLASH_TORCH (For Ruby use "::" instead of ".")
      String: torch

      The flash is turned on in torch mode.

      Property Access:

      • Instance: This property can be accessed via an instance object of this class:
        • myObject.flashMode
      • Default Instance: This property can be accessed via the default instance object of this class.
        • Javascript: Rho.Camera.flashMode
        • Ruby: Rho::Camera.flashMode

      maxHeight : INTEGER Read Only

      The maximum height of images which can be captured.

      Property Access:

      • Instance: This property can be accessed via an instance object of this class:
        • myObject.maxHeight
      • Default Instance: This property can be accessed via the default instance object of this class.
        • Javascript: Rho.Camera.maxHeight
        • Ruby: Rho::Camera.maxHeight

      maxWidth : INTEGER Read Only

      The maximum width of images which can be captured.

      Property Access:

      • Instance: This property can be accessed via an instance object of this class:
        • myObject.maxWidth
      • Default Instance: This property can be accessed via the default instance object of this class.
        • Javascript: Rho.Camera.maxWidth
        • Ruby: Rho::Camera.maxWidth

      outputFormat : STRING 4.0.0

      Specifies the way to return the captured image to the application.

      Default: image

      Possible Values (STRING):

      Constant: Rho.Camera.OUTPUT_FORMAT_IMAGE (For Ruby use "::" instead of ".")
      String: image

      The captured image is stored on the device. The callback associated with takePicture will contain the location of the image.

      Constant: Rho.Camera.OUTPUT_FORMAT_DATAURI (For Ruby use "::" instead of ".")
      String: dataUri

      Image will be returned as a Data URI object, this is a base 64 encoding of the image and can be used to easily embed the image on the page or store the image in a database.

      Platforms:

      Android,WM

      Property Access:

      • Instance: This property can be accessed via an instance object of this class:
        • myObject.outputFormat
      • Default Instance: This property can be accessed via the default instance object of this class.
        • Javascript: Rho.Camera.outputFormat
        • Ruby: Rho::Camera.outputFormat

      previewHeight : INTEGER 4.0.0

      In cases where the resident camera application on the device is not used this API is used to control the position of the viewfinder preview window when taking a photo.

      Property Access:

      • Instance: This property can be accessed via an instance object of this class:
        • myObject.previewHeight
      • Default Instance: This property can be accessed via the default instance object of this class.
        • Javascript: Rho.Camera.previewHeight
        • Ruby: Rho::Camera.previewHeight

      previewLeft : INTEGER 4.0.0

      Replaces:left

      In cases where the resident camera application on the device is not used this API is used to control the position of the viewfinder preview window when taking a photo.

      Property Access:

      • Instance: This property can be accessed via an instance object of this class:
        • myObject.previewLeft
      • Default Instance: This property can be accessed via the default instance object of this class.
        • Javascript: Rho.Camera.previewLeft
        • Ruby: Rho::Camera.previewLeft

      previewTop : INTEGER 4.0.0

      Replaces:top

      In cases where the resident camera application on the device is not used this API is used to control the position of the viewfinder preview window when taking a photo.

      Property Access:

      • Instance: This property can be accessed via an instance object of this class:
        • myObject.previewTop
      • Default Instance: This property can be accessed via the default instance object of this class.
        • Javascript: Rho.Camera.previewTop
        • Ruby: Rho::Camera.previewTop

      previewWidth : INTEGER 4.0.0

      In cases where the resident camera application on the device is not used this API is used to control the position of the viewfinder preview window when taking a photo.

      Property Access:

      • Instance: This property can be accessed via an instance object of this class:
        • myObject.previewWidth
      • Default Instance: This property can be accessed via the default instance object of this class.
        • Javascript: Rho.Camera.previewWidth
        • Ruby: Rho::Camera.previewWidth

      saveToDeviceGallery : BOOLEAN 2.0.0

      Replaces:save_to_shared_gallery

      If true, the picture you take will be added to the device photo gallery. At Android default value is true.

      Default: false

      Property Access:

      • Instance: This property can be accessed via an instance object of this class:
        • myObject.saveToDeviceGallery
      • Default Instance: This property can be accessed via the default instance object of this class.
        • Javascript: Rho.Camera.saveToDeviceGallery
        • Ruby: Rho::Camera.saveToDeviceGallery

      supportedSizeList : ARRAY Read Only

      List of resolutions supported by camera.

    • Object : HASH

      • width : INTEGER

      • height : INTEGER

      Property Access:

      • Instance: This property can be accessed via an instance object of this class:
        • myObject.supportedSizeList
      • Default Instance: This property can be accessed via the default instance object of this class.
        • Javascript: Rho.Camera.supportedSizeList
        • Ruby: Rho::Camera.supportedSizeList

      useSystemViewfinder : BOOLEAN 4.0.0

      Uses the system Camera application to take a picture instead of rhodes' camera. The system Camera application does not accept most rhodes' camera settings and can be adjusted by UI.

      Default: false

      Property Access:

      • Instance: This property can be accessed via an instance object of this class:
        • myObject.useSystemViewfinder
      • Default Instance: This property can be accessed via the default instance object of this class.
        • Javascript: Rho.Camera.useSystemViewfinder
        • Ruby: Rho::Camera.useSystemViewfinder

      Examples

      Take picture with default camera

      Take an image with as little code as possible, using all default values.

      function take_picture_with_default_camera() {
        // Capture an image from the default camera on the device, using the default image settings
        Rho.Camera.takePicture({}, picture_taken_callback);
      }
      
      function picture_taken_callback(params) {
        // Did we receive an image?
        if (params["status"]=="ok") {
          // Assuming we have an <img id="#captured_image"> tag, we will be able to see the image that was just captured
          $("#captured_image").attr("src", Rho.Application.expandDatabaseBlobFilePath(params["imageUri"]));
        }
      }
                         
                       
      def take_picture_with_default_camera
        # Capture an image from the default camera on the device, using the default image settings
        Rho::Camera.takePicture({}, :picture_taken_callback)
      end
        
      def picture_taken_callback
        # Did we really take a picture?
        if (@params["status"]=="ok")
          # If so, show it
          Rho::WebView.navigate(url_for(:action => :show_picture, :query => {:image => Rho::Application.expandDatabaseBlobFilePath(@params["imageUri"])}))
        else
          # Otherwise we are done here
          Rho::WebView.navigate(url_for(:action => :index))
        end
      end
                         
                       
      Choose which camera to use when taking images

      On devices with more than one camera, you can select which camera to use for taking pictures.

      <div id="camera_list">
      </div>
      
      
      var cameras = [];
      
      function choose_camera() {
        // get all available cameras
        cameras = Rho.Camera.enumerate();
      
        // build an HTML list
        var cameraList = "<ul>";
             
        for (var cameraIndex=0; cameraIndex<cameras.length; cameraIndex++) {
          var camera = cameras[cameraIndex];
          // Create a link for each camera with an onclick handler
          cameraList = cameraList +'<li><a href="#" class="take_picture_with_selected_camera" onclick="take_picture_with_camera('+cameraIndex+')">'+camera.cameraType+'</a></li>';
        }
        
        cameraList = cameraList+"</ul>";
        
        // make camera list visible to the user
        $("#camera_list").html(cameraList);
      }
      
      function take_picture_with_camera(cameraIndex) {
        var camera = cameras[cameraIndex];
        camera.takePicture({}, picture_taken_callback);
      }
                         
                       
      # controller.rb
      def choose_camera
        $cameras = Rho::Camera.enumerate
        render
      end
      
      def take_picture_using_chosen_camera
        camera = $cameras[@params["cameraIndex"].to_i]
        camera.takePicture({}, url_for(:action => :picture_taken_callback))
      end
      
      
      # choose_camera.erb
      <ul data-role="listview">
        <% $cameras.each_with_index do |camera, index| %>
          <li><a href="<%= url_for(:action => :take_picture_using_chosen_camera, :query => {:camera_index => index}) %>"><%= camera.cameraType %></li> 
        <% end %>
      </ul>
                         
                       
      Saving a picture to the device's gallery

      Apart from taking new pictures, you can also save images to the built-in gallery. In the following examples, the picture we are adding to the gallery is one that was just taken with the camera, but you can add any other image you can access by filename.

      function take_picture_and_save_it_to_gallery() {
        Rho.Camera.choosePicture({}, picture_taken_callback_save_to_gallery);
      }
      
      function picture_taken_callback_save_to_gallery(params) {
        if (params["status"]=="ok") {
          Rho.Camera.saveImageToDeviceGallery(Rho.Application.expandDatabaseBlobFilePath(params["imageUri"]));
            
          alert("Image saved to gallery");
        }
      }
                         
                       
      def take_picture_and_save_it_to_gallery
        Rho::Camera.choosePicture({}, url_for(:action => :picture_taken_callback_save_to_gallery))    
      end
        
      def picture_taken_callback_save_to_gallery
        # Did we really take a picture?
        if (@params["status"]=="ok")
          # If so, save it to the gallery
          Rho::Camera.saveImageToDeviceGallery(Rho::Application.expandDatabaseBlobFilePath(@params["imageUri"]))
        end
      
        Rho::WebView.navigate(url_for(:action => :index))
      
      end  
                         
                       
      Control image properties

      You can tweak multiple options to get an image exactly as you need it

      function control_image_properties() {
        // Instead of accepting the defaults, let's set some properties to our liking
        
        // We will ask for a PNG file...
        Rho.Camera.compressionFormat = "png";
        
        // ...a particular image size...
        Rho.Camera.desiredWidth = 1024;
        Rho.Camera.desiredHeight = 768;
        
        // ...and force the flash to be used
        Rho.Camera.flashMode = "on";
        
        // Now, take the picture
        Rho.Camera.takePicture({}, picture_taken_callback);      
      }
      
      function picture_taken_callback(params) {
        // Did we receive an image?
        if (params["status"]=="ok") {
          // show it in our <img id="captured_image"> tag
          $("#captured_image").attr("src", Rho.Application.expandDatabaseBlobFilePath(params["imageUri"]));
        }
      
      }
                         
                       
      def control_image_properties
        # Instead of accepting the defaults, let's set some properties to our liking
          
        # We will ask for a PNG file...
        Rho::Camera.compressionFormat = "png"
          
        # ...a particular image size...
        Rho::Camera.desiredWidth = 1024
        Rho::Camera.desiredHeight = 768
          
        # ...and force the flash to be used
        Rho::Camera.flashMode = "on"
          
        # Now, take the picture
        Rho::Camera.takePicture({}, :picture_taken_callback)    
      end
      
      def picture_taken_callback
        # Did we really take a picture?
        if (@params["status"]=="ok")
          # If so, show it
          Rho::WebView.navigate(url_for(:action => :show_picture, :query => {:image => Rho::Application.expandDatabaseBlobFilePath(@params["imageUri"])}))
        else
          # Otherwise we are done here
          Rho::WebView.navigate(url_for(:action => :index))
        end
      end
                         
                       
      Determine camera capabilities

      You can get all available camera properties in a single call.

      function determine_camera_capabilities() {
        var capabilitiesList = "<ul>"; 
      
        // Get all capabilities of the camera...
        var capabilities = Rho.Camera.getAllProperties();
      
        // ... compose a nicely formatted list with their names and values ...
        for (var capability in capabilities) {
          capabilitiesList+="<li>"+capability+": "+capabilities[capability]+"</li>";
        }
      
        capabilitiesList += "</ul>";
        
        // ... and show it
        $("#camera_capabilities").html(capabilitiesList);
      }
                         
                       
      # controller.rb
      
      def determine_camera_capabilities
        # Get all camera properties
        @properties = Rho::Camera.getAllProperties
        render
      end
      
      # determine_camera_capabilities.erb
          <ul data-role="listview">
          
          <% @properties.each_pair do |name,value| %>
            <li><%= name %> : <%= value %></li>
          <% end %>
      
          </ul>
                         
                       
      Select picture from device gallery

      Apart from taking new pictures, the Camera API also lets you access existing images on the device’s gallery.

      function select_picture_from_gallery() {
        Rho.Camera.choose_picture({}, picture_taken_callback);
      }
      
      function picture_taken_callback(params) {
        // Did we receive an image?
        if (params["status"]=="ok") {
          // Show it in an <img> tag
          $("#captured_image").attr("src", Rho.Application.expandDatabaseBlobFilePath(params["imageUri"]));
        }
      }
                         
                       
      def select_picture_from_gallery 
        Rho::Camera.choosePicture({}, url_for(:action => :picture_taken_callback))
      end
      
      def picture_taken_callback
        # Did we really take a picture?
        if (@params["status"]=="ok")
          # If so, show it
          Rho::WebView.navigate(url_for(:action => :show_picture, :query => {:image => Rho::Application.expandDatabaseBlobFilePath(@params["imageUri"])}))
        else
          # Otherwise we are done here
          Rho::WebView.navigate(url_for(:action => :index))
        end
      end