Manuel_Rodrigues
Manuel_Rodrigues

Reputation: 560

get image hight and with in Titanium

I need to get the hight and width of an image from a server that i need to show directly to the user.

so e have tried to create a imageView and put the image in it so i could read the hight and width of the imageView

var image = Ti.UI.createImageView({
                image : //host Site,
                width : "auto",
                height : "auto"
            });

var hight = image.height;
var width = image.width;

but it returns always hight = auto and width = auto.

how can i get the height and width like fro example hight = 630 and width = 320?

Upvotes: 0

Views: 120

Answers (2)

Manuel_Rodrigues
Manuel_Rodrigues

Reputation: 560

I figured out how to get the hight and width of an image

 var image = Ti.UI.createImageView({
                image : //host Site,
                width : "auto",
                height : "auto"
            });

var hight = image.toBlob().height;
var width = image.toBlob().width;

i hade only to add toBolob() where i'm trying to get the height and width

Upvotes: 0

Thomas Lemaitre
Thomas Lemaitre

Reputation: 1154

First, listen to the load or postlayout event : http://docs.appcelerator.com/platform/latest/#!/api/Titanium.UI.ImageView-event-load Instead this event, you can get the Dimension of the ImageView : http://docs.appcelerator.com/platform/latest/#!/api/Titanium.UI.ImageView-method-getRect like this :

var rect = image.getRect();

Upvotes: 1

Related Questions