blob width and height bug
I need to know the width and height of an image to set a imageView depending on whether a picture is portrait or landscape.
I've taken a look at image_view_scaling.js and the following works
var imageView1 = Titanium.UI.createImageView({
url:'http://www.appcelerator.com/wp-content/uploads/2009/06/titanium_desk.png',
width: 'auto',
height: 'auto',
});
view1.add(imageView1)
var blob = imageView1.toBlob();
alert(blob.width + "x" + blob.height);
The problem is that my images are local and I'm therefor using a 'file'. The following code…
var fileImage = Ti.Filesystem.getFile(Titanium.Filesystem.resourcesDirectory, win.objProp1[win.galleryNumber].photos[0]);
var imageView1 = Titanium.UI.createImageView({
image:fileImage,
width: 'auto',
height: 'auto',
});
view1.add(imageView1)
var blob = imageView1.toBlob();
alert(blob.width + "x" + blob.height);
Generates this error
While executing Timer, received script error. 'Result of expression 'blob' [null] is not an object.
Any ideas what's wrong?
3 Answers
-
Accepted Answer
try using .toImage() instead of toBlob() ?
-
try .addEventListener("load", function(e) { var blob = e.source.toBlob(); });
-
Thanks - worked like a charm.