Titanium Community Questions & Answer Archive

We felt that 6+ years of knowledge should not die so this is the Titanium Community Questions & Answer Archive

API - Camera?

Hi,

is it possible to take a picture (photo) with the camera? I havn't found anything similar in the API.

If not ATM, is it in the roadmap?

— asked September 29th 2010 by Thomas Robertz
  • api
  • camera
  • photo
  • photograph
  • picture
0 Comments

1 Answer

  • Accepted Answer

    Check the Kitchen Sink, there are several examples of using the camera. For instance, here is saving it to a file….they also have gallery if you need.

    var win = Titanium.UI.currentWindow;
    
    
    Titanium.Media.showCamera({
    
        success:function(event)
        {
            var cropRect = event.cropRect;
            var image = event.media;
    
            var f = Titanium.Filesystem.getFile(Titanium.Filesystem.applicationDataDirectory,'camera_photo.png');
            f.write(image);
            win.backgroundImage = f.nativePath;
        },
        cancel:function()
        {
    
        },
        error:function(error)
        {
            // create alert
            var a = Titanium.UI.createAlertDialog({title:'Camera'});
    
            // set message
            if (error.code == Titanium.Media.NO_CAMERA)
            {
                a.setMessage('Device does not have video recording capabilities');
            }
            else
            {
                a.setMessage('Unexpected error: ' + error.code);
            }
    
            // show alert
            a.show();
        },
        allowEditing:true
    });
    
    — answered September 29th 2010 by Mike Robinson
    permalink
    0 Comments
The ownership of individual contributions to this community generated content is retained by the authors of their contributions.
All trademarks remain the property of the respective owner.