[英]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. 我从aws获取图像并将它们分配给QPixmap变量。 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.
我将它们转换为QImage并使用了byteCount方法,尽管图像的文件大小为735字节,但它返回3952字节,它等于width * height * 4。
When you load image into QPixmap
or QImage
, it is converted from file format to internal representation. 当您将图像加载到
QPixmap
或QImage
,它会从文件格式转换为内部表示形式。 Because of that, QImage.byteCount()
returns number of bytes used to store image. 因此,
QImage.byteCount()
返回用于存储图像的字节数。 As you already mentioned, it is equals to width*height*4. 如您已经提到的,它等于宽*高* 4。 Here, digit
4
is color depth (bytes per pixel). 此处,数字
4
是色深(每像素字节)。 You can get it via QImage.depth()
method. 您可以通过
QImage.depth()
方法获取它。 Note that it will return number of bits, so you have to divide it by 8 to get bytes. 请注意,它将返回位数,因此您必须将其除以8以获得字节。
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). 因此,如果要获取文件大小,则可以使用
len(data)
(如ekhumoro所建议len(data)
,也可以将其加载到QFile
并调用size()
(如果已将其保存在硬盘上)。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.