Titanium JIRA Archive
Titanium SDK/CLI (TIMOB)

[TIMOB-8481] Android: blob representing an image has height and width properties always 0

GitHub Issuen/a
TypeBug
PriorityHigh
StatusClosed
ResolutionCannot Reproduce
Resolution Date2012-09-06T14:13:44.000+0000
Affected Version/sRelease 2.0.0, Release 1.8.1, Release 1.8.2, Release 2.0.1
Fix Version/sn/a
ComponentsAndroid
LabelsSupportTeam, api
ReporterFederico Casali
AssigneeKarl Rowley
Created2012-02-27T10:51:19.000+0000
Updated2019-05-28T07:24:30.000+0000

Description

Problem

Returned values relative to Width or Height of a blob representing an image, are 0.

Test Case

var win = Ti.UI.createWindow({
	backgroundColor:'gray'
});


Ti.Media.openPhotoGallery({
    success: function(e) {
        alert('e.media.width:' + e.media.width +
         '\n e.media.height:' + e.media.height +
         '\n e.media.mimeType:' + e.media.mimeType);
    }
});


win.open();

Values displayed: W/TiAPI ( 5241): e.media.height: 0 W/TiAPI ( 5241): e.media.width: 0 W/TiAPI ( 5241): e.media.mimeType: image/jpeg Customer have opened a question on the developer q&a: http://developer.appcelerator.com/question/132278/timediaopenphotogallery-image-properties-on-android

Comments

  1. Dan Cash 2012-02-28

    I just tried the code in sdk version 2.0.0.v20120227100134 and the issue is still there.
  2. Dan Cash 2012-03-01

    Ran the code above using the just released sdk 1.8.2. It still returns 0 for the blob height and width when the mime type is an image.
  3. Dan Cash 2012-03-05

    I have a client waiting for an update to their application that I can't complete until this is working.
  4. Ronald Treur 2012-03-27

    I've stumbled upon the exact same problem. The blob containing the image does have a size and a correct mime-type (image/jpeg), but the width and height are both equal to 0. Environment: Android 2.3.3 V8 runtime Titanium SDK 1.8.2 Mac OS X 10.6.8 I was unable to check this on an actual Android phone, but the Simulator suffered from this issue.
  5. Federico Casali 2012-04-01

  6. Zsombor Papp 2012-04-05

    Perhaps this goes without saying, but the problem is also present when the image data is simply loaded from a file. On the other hand, the blob returned by the ImageFactory module's imageAsResized function does have the width/height set properly. It's probably a huge waste of resources, but I ended up using this function as a workaround. Did anyone find a lighter weight workaround?
  7. Dan Cash 2012-04-05

    I haven't figured out a work around for this. Do you have some sample code for using the imageAsResized function to get the width/height?
  8. Zsombor Papp 2012-04-05

    Sample code: var ImageFactory = require('ti.imagefactory'); var imageBlob = ImageFactory.imageAsResized(photoFile.read(), {}); Obviously photoFile.read() can be replaced with any blob holding image data; this is just my usecase (that second line used to be imageBlob = photoFile.read()).
  9. Ronald Treur 2012-04-11

    Thanks for the interim solution Zsombor! Unfortunately it crashes my app on our Android device (seems to be a problem with allocating memory). It runs perfectly in the Emulator though.. I finally got my hands on a brand new Android device (HTC Wildfire S), running Android 2.3.3. I can now confirm that this problem occurs both when selecting photo's from the gallery and when making a new photo using the device's camera. I hope someone is going to give this problem some attention, because this problem makes uploading images from an Android phone near impossible! --- Quick update: Using the compress-method from the ImageFactory didn't crash my device and also yielded a blob with width/height-properties. I currently use the following code: event.media = ImageFactory.compress(event.media, 0.8); Btw: ImageFactory is a freely downloadable module, made by the Appcelerator team: https://marketplace.appcelerator.com/apps/1184/reviews
  10. Dan Cash 2012-04-11

    Thanks for the work around advice Zsombor and Ronald. I am able to get the dimensions of an image by using the ImageFactory compress method: var img = ImageFactory.compress(event.media, 1.0); Hopefully, this bug will get fixed soon and I can remove this work-around.
  11. Junaid Younus 2012-05-22

    Tested with 2.0.1GA2 on a Samsung Galaxy S2, issue still exists.
  12. Ash Connell 2012-06-26

    Thank god, I spent 4 hours looking for a way to resize images and when I finally found ImageFactory and then couldn't get an image blobs' width, i was going to shoot myself. Dan Cash's method works a charm: var img = ImageFactory.compress(event.media, 1.0);
  13. Karl Rowley 2012-09-06

    Can't reproduce on SDK version 3.0 with Samsung Galaxy S2 (AT&T) Android 2.3, or with Samsung Galaxy S3 (Sprint) Android 4.0.
  14. Neeraj Gupta 2012-09-06

    @Ash, Dan, Ronald, Zsombor - Please update this ticket if you can reproduce this issue with the latest release (master; 3.0.0).
  15. Lee Morris 2017-03-27

    Closing ticket as I am unable to reproduce this issue with the following environment; Pixel (7.1) MacOS 10.11.6 (15G31) Studio 4.8.1.201612050850 Ti SDK 6.0.3 GA Appc NPM 4.2.8 Appc CLI 6.1.0 Ti CLI 5.0.11 Alloy 1.9.5 Arrow 1.10.1 Xcode 8.2 (8C38) Node v4.6.0 Java 1.7.0_80
  16. Rodolfo Perottoni 2019-05-28

    This issue is happening again on SDK 8. Downloaded images always return height and width 0 when trying to access it through blob.height and blob.width. Seen on SDK 8.1.0.v20190510141905.

JSON Source