Search code examples
imagepngheightwidthtitanium

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.


Solution

  • 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;