Problem
Cannot get the size (height and width) of the image in the imageview after it has finished loading from a remote location.
Sample Code
Please run the code below to reproduce the issue
{noformat}
//create component instance
var self = Ti.UI.createWindow({
backgroundColor : '#ffffff',
navBarHidden : true,
exitOnClose : true
});
//construct UI
var boundingBox = Ti.UI.createView({
backgroundColor : 'red',
width : Ti.UI.SIZE,
height : Ti.UI.SIZE
});
var sampleImageFromFarAway = Ti.UI.createImageView({
image : '
https://www.google.com/images/logo_sm.gif',
height : Ti.UI.SIZE, //'auto',
width : Ti.UI.SIZE, //'auto',
preventDefaultImage : true,
borderAroundMeView : boundingBox
});
var lateImageLoadingHandler = function(e) {
Ti.API.info('1 Height: ' + sampleImageFromFarAway.size.height + ' Width: ' + sampleImageFromFarAway.size.width);
var blob = sampleImageFromFarAway.toImage();
Ti.API.info('Height after toImage: ' + blob.height + ' Width after toImage: ' + blob.width);
var borderView = sampleImageFromFarAway.borderAroundMeView;
borderView.width = blob.width + 24;
borderView.height = blob.height + 24;
}
sampleImageFromFarAway.addEventListener('load', lateImageLoadingHandler);
boundingBox.add(sampleImageFromFarAway);
self.add(boundingBox);
self.open();
{noformat}
Also tried converting the image to toImage() as seen above but still could not get the correct height and width of the image.
Actual Output
Please see the screenshot attached. The height and width are returned as 0 and after doing a toImage() are returned as a random "100"
Also attached is the output of the same code in iOS.
Sample image is 150 x 55
Fixed in 2.1.0.7d81569.
Tested with 2.1.0.v20120615104152 with Droid 3 2.3.4