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
I just tried the code in sdk version 2.0.0.v20120227100134 and the issue is still there.
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.
I have a client waiting for an update to their application that I can't complete until this is working.
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.
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?
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?
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()).
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
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.
Tested with 2.0.1GA2 on a Samsung Galaxy S2, issue still exists.
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);
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.
@Ash, Dan, Ronald, Zsombor - Please update this ticket if you can reproduce this issue with the latest release (master; 3.0.0).
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
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.