Unable to display captured photo to view

You must Login before you can answer or comment on any questions.

titanium mobile sdk 2.0

iphone sdk 5.1

Hi,

I grabbed this code from the kitchen sink but unable to display the captured photo to view

getPhoto.addEventListener('click', function(){
 
    var win = Titanium.UI.currentWindow;
    Titanium.Media.showCamera({
        success:function(event)
    {
        var cropRect = event.cropRect;
        var image = event.media;
 
        Ti.API.debug('Our type was: '+event.mediaType);
    if(event.mediaType == Ti.Media.MEDIA_TYPE_PHOTO)
    {
        var imageView = Ti.UI.createImageView({
        width:win.size.width,
        height:win.size.height,
        image:event.media
    });
    win.add(imageView);
    }
        else
    {
        alert("got the wrong type back ="+event.mediaType);
    }
    },
        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('Please run this test on device');
    }
        else
    {
        a.setMessage('Unexpected error: ' + error.code);
    }
 
    // show alert
    a.show();
    },
        saveToPhotoGallery:true,
        allowEditing:true,
        mediaTypes:[Ti.Media.MEDIA_TYPE_VIDEO,Ti.Media.MEDIA_TYPE_PHOTO]
    });
}
It captures a photo but after that it doesn't show in the view. What am i doing wrong?

1 Answer

From what I read, you are trying to add a new image view once the picture is taken.

Try to create your imageView before calling the showCamera function. I suggest you set it a different background color so you know it was created successfully (for testing purposes).

Your Answer

Think you can help? Login to answer this question!