简体   繁体   中英

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.

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).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM