我有一个列表,它包含一个目录的图像路径。图像主要是使用具有.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下载图片,没有文件格式化。
现在,如何通过更改图像的扩展来捕捉警告并对其采取行动?
发布于 2020-01-20 09:47:56
使用self.scaled_image.isNull()检查缩放是否成功:
if (not self.scaled_image.isNull()):
#set it to label
else:
#do something else if you wanthttps://stackoverflow.com/questions/59818927
复制相似问题