Skip to main content
 首页 » 编程设计

python之在 QLabel 中渲染 WSQ 图像的最佳方式是什么

2025年05月04日7findumars

我正在尝试在 PyQt5 的 QLabel 中渲染 WSQ 图像。 WSQ 图像位于 zip 文件中的 xml 文件中。这是我的方法:

import zipfile 
import xml.etree.cElementTree as ET 
import base64.b64decode as b64decode 
from PyQt5 import QtGui, QtWidgets 
... 
try: 
    with zipfile.ZipFile(zfilename) as src_zip: 
        root = ET.fromstring(src_zip.open(xmlfilename).read()) 
except zipfile.BadZipFile as e: 
    root = None 
finger_prints = [] 
if root: 
    for data in root.findall('.//Demographics/FingerData'): 
        finger_prints.append(b64decode(data.find('FingerprintImage').text)) 
... 
finger_data = finger_prints.pop() 
pixmap = QtGui.QPixmap() 
pixmap.loadFromData(finger_data, 'WSQ') # freezes 
QtWidgets.QLabel().setPixmap(pixmap) 

第二行也是最后一行导致程序卡住/挂起,但如果我这样做:

with file('/tmp/finger_print.wsq', 'wb') as f: 
    f.write(finger_data) 

我可以在 WSQ 查看器中查看图像。我知道 Qt 有针对不同图像格式的插件,是否有我缺少的图像插件?

预先感谢您的帮助。

-亚伯拉罕。

请您参考如下方法:

image formats Qt 默认支持的是:

 Format  Description                            Qt's support 
 BMP     Windows Bitmap                         Read/write 
 GIF     Graphic Interchange Format (optional)  Read 
 JPG     Joint Photographic Experts Group       Read/write 
 JPEG    Joint Photographic Experts Group       Read/write 
 PNG     Portable Network Graphics              Read/write 
 PBM     Portable Bitmap                        Read 
 PGM     Portable Graymap                       Read 
 PPM     Portable Pixmap                        Read/write 
 XBM     X11 Bitmap                             Read/write 
 XPM     X11 Pixmap                             Read/write 

所以你要么必须写一个custom Qt image plugin ,或者以某种方式将图像数据转换为 Qt 可以理解的格式之一。