Getting Width / Height In Android For Ti.Media.openPhotoGallery / Ti.Media.showCamera

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

Hi,

I see this question asked a number of times but no one seems to have an answer that works. All the questions are many months old so I thought I would ask again.

This is a question about Android not iPhone. Everything works perfectly in iPhone.

When calling Ti.Media.openPhotoGallery / Ti.Media.showCamera the blob that is returned "event.media" never has event.media.width or event.media.height set. It does in iPhone. How can I get the width and the height of the image that gets returned in Android?

Ti.Media.openPhotoGallery({
        mediaTypes: [ Ti.Media.MEDIA_TYPE_PHOTO ],
        allowEditing: false,
        saveToPhotoGallery: true,
 
        success: function(event)
        {                   
            alert(event.media.width); <------ Always zero in Android, returns the correct width in iPhone
        }
});
Thanks in advance for any help.

— asked 12 months ago by Spicer Matthews
1 Comment
  • Hi, I have the same problem. Did you find a solution?

    — commented 12 months ago by Paolo Perrone

1 Answer

Hi Spicer,

Try this code....

Ti.Media.openPhotoGallery({
    mediaTypes : [Ti.Media.MEDIA_TYPE_PHOTO],
    allowEditing : false,
    saveToPhotoGallery : true,
 
    success : function(event) {
        var imgPhoto = Ti.UI.createImageView({
            height : 'auto',
            width : 'auto',
            zIndex : -2345,
            image : event.media
        });
        win.add(imgPhoto);
        var i = imgPhoto.toImage();
        alert("Height:" + i.height + "  width:" + i.width);
    }
});

— answered 12 months ago by Nitin Chavda
answer permalink
1 Comment
  • Thanks for the help. Afraid I got the same result. "Height: 1 Width: 1". Seems android really wants to keep the height and width a secret.

    — commented 12 months ago by Spicer Matthews

Your Answer

Think you can help? Login to answer this question!