Welcome!

Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

Native Development

Reply
Highlighted
Developer
Posts: 169
Registered: ‎03-25-2011
My Device: Playbook, Z10 L.E.
My Carrier: Vodafone NL

[tip] How to read loaded image dimensions via ImageView on QML

Hi guys,

 

The Cascades framework has some features that makes developing for it really easy and cool. But since it's a very young framework, it's APIs are still limiting some times. Today, it took me half an hour just to find out how to read the dimensions of an image loaded via ImageView. 

 

Here's how to do it in QML:

ImageView {
    id: myImageView
    attachedObjects: [
        ImageTracker {
            id: tracker
            image: "images/image.png"
            onStateChanged: { 
                if (state == ResourceState.Loaded)  {
                    // Images that are bigger than 2048x2048 px will not be displayed!
                    if(tracker.width <= 2048 && tracker.height <= 2048) {
                       myImageView.image = tracker.image;
                    }
                    else {
                        showErrorMessage("Image is too big!");
                    }
                }
            }
        }
    ]
}

 In my opinion, this is ridiculously complex for such a simple thing. It should be something simple like myImageView.image.width or myImageView.imageWidth. 

 

I created a new feature request. Please vote it up if you agree with me. I hope this help other people to save some precious time.

 

Cheers!

Cheers!