Emre Külah
Emre Külah

Reputation: 54

How can I find the file size of image which is read as QPixmap?

I get images from aws and assign them to QPixmap variables. I want to show their information as width height and file size. However I could not find a way to get file size of them. I converted them to QImage and used byteCount method however, although the file size of the image is 735 byte, it returns 3952 byte which is equal to width*height*4.

Upvotes: 0

Views: 1546

Answers (1)

mFoxRU
mFoxRU

Reputation: 490

When you load image into QPixmap or QImage, it is converted from file format to internal representation. Because of that, QImage.byteCount() returns number of bytes used to store image. As you already mentioned, it is equals to width*height*4. Here, digit 4 is color depth (bytes per pixel). You can get it via QImage.depth() method. Note that it will return number of bits, so you have to divide it by 8 to get bytes.

So, if you want to get file size, you can either use len(data) (as suggested by ekhumoro) or load it to QFile and call size() (if you have/save it on hard drive).

Upvotes: 1

Related Questions