Titanium.Media.showCamera

Description

Presents the camera interface to the user to let them take a photo

API Information

Description Start the camera for capturing an image.
Syntax [window] Titanium.Media.showCamera
Arguments
  1. options - (object) hash/dictionary for camera options.
Returns void
Available Since 0.4
Supported Platforms
android 1.5
iphone 2.2.1, 3.0, 3.1

Examples

Javascript
// Taken from the kitchen sink app 0.8.1

//
// show camera
//
function showCamera()
{
    Titanium.Media.showCamera({

        success:function(image,details)
        {
            var win = Titanium.UI.createWindow({url:'image.html'});
            Titanium.App.Properties.setString('photo',image.url);
            Titanium.App.Properties.setBool('movie',false);

            if (details)
            {
                Titanium.App.Properties.setString('x',details.cropRect.x);
                Titanium.App.Properties.setString('y',details.cropRect.y);
                Titanium.App.Properties.setString('height',details.cropRect.height);
                Titanium.App.Properties.setString('width',details.cropRect.width);

            }
            else
            {
                Titanium.App.Properties.setString('x',0);
                Titanium.App.Properties.setString('y',0);
                Titanium.App.Properties.setString('height',image.height);
                Titanium.App.Properties.setString('width',image.width);
            }

            win.open();

        },
        cancel:function()
        {

        },
        error:function(error)
        {
            // create alert
            var a = Titanium.UI.createAlertDialog();

            // set title
            a.setTitle('Camera Error');

            // set message
            if (error.code == Titanium.Media.NO_CAMERA)
            {
                a.setMessage('Device does not have camera');
            }
            else
            {
                a.setMessage('Unexpected error: ' + error.code);
            }

            // set button names
            a.setButtonNames(['OK']);

            // show alert
            a.show();
        },
        allowImageEditing:true
    });
};

Last Modified on January 23, 2010, 03:01 AM by Leo Lapworth Edit | History