Titanium Community Questions & Answer Archive

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

How to pass image taken with camera to another window

Is it possible, without saving to photo gallery, to pass image data from the success result of Ti.Media.showCamera to a new window so that it can be assigned to an imageview's image property?

Kitchensink demo camera_overlay.js shows assigning the event.media object to the imageview image property in the same window. But can't see anywhere how to pass event.media to a new window.

— asked December 2nd 2010 by Gary Crook
  • camera
  • images
  • iphone
  • mobile

1 Answer

  • not the most elegant solution, but it does work.. better solution described at bottom

    1) Create a new Titanium Project

    2) Paste this code after the tabGroup.open() statement

    // create image view
    var imageView = Titanium.UI.createImageView({
    // add view to the window
    // create an eventListener on the open of win2 that
    // will assign the image to the window on the open
    // event.
    win2.addEventListener('open', function(e){
        win2.imageView.image = win2.imageBlob;
        success: function(event)
            var cropRect = event.cropRect;
            var image = event.media;
           // save the imageBlog on the window along with the view
           // this shows that the window could be in a separate .js
            win2.imageBlob = event.media;
            win2.imageView = imageView;
            // 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');
                a.setMessage('Unexpected error: ' + error.code);
            // show alert

    If it were me, I would save the imageblob to a temp file and then fire an event with the file name being passed to the window/or imageView that I want to render the image.

    I would do it that way because the Camera is known to be a memory hog on the iPhone and the app will start trying to purge things from memory which might cause additional problems for you.

    — answered December 3rd 2010 by Aaron Saunders
    1 Comment
    • Many thanks, I will give it a go.

      — commented December 3rd 2010 by Gary Crook
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.