Reputation: 2088
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
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