2014-01-14 176 views
2

我想在PyQt5中的QLabel中呈现WSQ图像。 WSQ图像位于一个zip文件中的xml文件中。这里是我的方法:什么是在QLabel中呈现WSQ图像的最佳方式

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有不同图像格式的插件,是否有我缺少的图像插件?

在此先感谢您的帮助。

-Abraham。

+0

嗨@安德鲁 - 巴伯,我已经重新构思了我的问题,甚至改变了标题,如果你再看一下,我会很感激。如果它仍然是题外话,我会诚心诚意地采取。 –

回答

1

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的理解之一。

相关问题