简体   繁体   English

如何找到作为QPixmap读取的图像的文件大小?

[英]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. 当您将图像加载到QPixmapQImage ,它会从文件格式转换为内部表示形式。 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.

相关问题 如何使QLabel与其显示的QPixmap的大小完全相同? - How can I have a QLabel exactly the size of the QPixmap it is showing? 如何找到要读取的文件? - how can I find the file to read? 如何从不同的子目录读取多个 csv 文件并找到具有该值的 csv 文件? - How can I read multiple csv file from different sub directories and find the csv file which has the value? 设置 label 大小与 QPixmap 图像一样大 - set label size as big as QPixmap image 如何使用文件夹中的 pandas 读取任何 excel 文件? - How can I read any excel file with pandas which is in folder? 如何读取二进制文件并将数据转换为图像? - How can I read a binary file and turn the data into an image? 如何在Tensorflow中读取远程图像文件进行分类? - How can I read in a remote image file in Tensorflow for classification? 我如何使用 Pyplot 从 memory 而不是文件中读取图像? - How can i read an image with Pyplot from memory instead of a file? QPixmap:如何在addPixmap中增加图片的大小? - QPixmap: How to increase the size of the picture in addPixmap? Python Flask-如何在将图像上传到Amazon s3之前读取图像的大小 - Python Flask- how can I read the size of an image before uploading it to Amazon s3
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM