Curtwagner1984
Curtwagner1984

Reputation: 2088

Is it possible to get loaded image original dimensions and byte size in QML?

If I have an image item in QML, is it possible for me to find out the original dimensions of the image and its byte size?

For example, if I have the following QML:

import QtQuick 2.0

Image {
    source: "http://someURL.jpg"
    asynchronous: true
    sourceSize.width: 800
    sourceSize.height: 600
}

Can I get the image's original dimensions and it's byte size after it is completely loaded? I wasn't able to find such properties in the documentation of Image.

Upvotes: 0

Views: 2685

Answers (1)

Alexander V
Alexander V

Reputation: 8698

If I have an image item in QML, is it possible for me to find out the original dimensions of the image and its byte size?

The problem with async load is that we need to know the moment when the image is ready and there is a way to do so. QtQuick Image has property status to which we can attach the signal:

Image {
    source: "http://someURL.jpg"
    asynchronous: true
    onStatusChanged: {
      if (status == Image.Ready) {
         console.log('Loaded: sourceSize ==', sourceSize);
      }
    }
}

So we should rather read from sourceSize but when ready.

Upvotes: 4

Related Questions