Titanium JIRA Archive
Titanium SDK/CLI (TIMOB)

[TIMOB-9270] Android: Cannot get size of the remote image in imageview after load completes

GitHub Issuen/a
TypeBug
PriorityHigh
StatusClosed
ResolutionFixed
Resolution Date2012-06-08T14:50:26.000+0000
Affected Version/sRelease 2.0.1
Fix Version/sRelease 2.1.0, Sprint 2012-12 Core
ComponentsAndroid
LabelsSupportTeam, core, qeport
ReporterVarun Joshi
AssigneeStephen Tramer
Created2012-05-24T19:21:44.000+0000
Updated2012-06-15T14:51:08.000+0000

Description

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.

Attachments

FileDateSize
ScreenShot-Android.png2012-05-24T19:21:44.000+0000171944
ScreenShot-iOS.png2012-05-24T19:21:44.000+0000141868

Comments

  1. Stephen Tramer 2012-06-08

    Sample image is 150 x 55
  2. Stephen Tramer 2012-06-08

    Fixed in 2.1.0.7d81569.
  3. Natalie Huynh 2012-06-15

    Tested with 2.1.0.v20120615104152 with Droid 3 2.3.4

JSON Source