我有一个包含目录图像路径的列表。图像的下载大多使用扩展名为.jpg和.png的请求。
def display_image_label(self, image_path):
self.scaled_image = QPixmap(image_path).scaled(600, 400, Qt.IgnoreAspectRatio, Qt.FastTransformation)
self.image_label.setPixmap(self.scaled_image)
[现在的问题是,很少加载.jpg图片显示QPixmap::scaled: Pixmap is a null pixmap
,因为扩展名应该是.png,因为我已经检查过将扩展名从.jpg更改为.png会加载图像。我直接使用requests下载图像,未完成文件格式化。
现在,如何通过更改图像的扩展名来捕获警告并采取相应措施?
使用self.scaled_image.isNull()检查缩放是否成功像:
if (not self.scaled_image.isNull()):
#set it to label
else:
#do something else if you want