Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Titanium: get png height without creating ImageView

Is there a way to get a .png height without creating ImageView?

The methods I found on google require createImageView first and then doing a .height.

I want to avoid creating ImageView because I'm going to createImageView after I get the height of the png and perform some changes.

Or rather, I will be using the height value during the var imagevariablename = Ti.UI.createImageView itself, so I can't using imagevariablename.height because the declaration of var imagevariablename is not done yet.

like image 916
John Tan Avatar asked Dec 26 '11 10:12

John Tan


2 Answers

I don't know of any way to get the height / width of an image without creating an imageView in Titanium. In my app, I create a temporary image view and read the attributes without ever adding it to a view / window. Then you can create the 'real' image view once you know the size:

var imageTemp = Ti.UI.createImageView({
  image : someFile.read(),
  height:'auto',
  width:'auto'
});
Ti.API.info( "height=" + imageTemp.size.height);
Ti.API.info( "width=" + imageTemp.size.width);
imageTemp = null;
like image 111
Jeff Bonnes Avatar answered Sep 23 '22 14:09

Jeff Bonnes


Try this code

var imageTemp = Ti.UI.createImageView({
    image : <image>,
    height:'auto',
    width:'auto'
}),
imageSize = imageTemp.toImage();

Ti.API.info( "height=" + imageSize.height);
Ti.API.info( "width=" + imageSize.width);

imageTemp = imageSize = null;
like image 36
Code-Source Avatar answered Sep 22 '22 14:09

Code-Source