Titanium Community Questions & Answer Archive

We felt that 6+ years of knowledge should not die so this is the Titanium Community Questions & Answer Archive

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?

— asked April 4th 2010 by Phi Chong
  • blob
  • image
  • imageview
  • iphone
0 Comments

3 Answers

  • Accepted Answer

    try using .toImage() instead of toBlob() ?

    — answered April 5th 2010 by Kosso
    permalink
    0 Comments
  • try .addEventListener("load", function(e) { var blob = e.source.toBlob(); });

    — answered November 2nd 2012 by Y K
    permalink
    1 Comment
    • Thanks, Y K!

      — commented January 23rd 2013 by Ilya Butylsky
  • Thanks - worked like a charm.

    — answered April 5th 2010 by Phi Chong
    permalink
    0 Comments
The ownership of individual contributions to this community generated content is retained by the authors of their contributions.
All trademarks remain the property of the respective owner.