使用FreeImage在PySide中加载文件
我正在尝试使用 smc.FreeImage 来加载 .NEF 文件(尼康相机的原始格式),然后用 PySide 显示出来。
我找到一个例子,它可以很好地加载和显示一个注释过的 .JPG 文件,但当我把图像换成 .NEF 文件时,程序就崩溃了。
我加了一个打印语句,打印 pixmap.getInfoHeader,以确保 .NEF 文件确实加载成功,输出窗口里显示了正确的头信息。
我该如何把读取到的 pixmap = FI.Image 转换成 PySide 能理解的格式呢?我看到有人使用 numpy 和 PIL 的 tostring 方法,但这些例子似乎都没有涉及到我的情况。
import sys
from PySide import QtGui, QtCore
from smc import freeimage as FI
class Example(QtGui.QWidget):
def __init__(self):
super(Example, self).__init__()
self.initUI()
def initUI(self):
hbox = QtGui.QHBoxLayout(self)
#pixmap = QtGui.QPixmap("Somefile.jpg")
pixmap = FI.Image("Anotherfile.NEF")
print( pixmap.getInfoHeader() )
lbl = QtGui.QLabel(self)
lbl.setPixmap(pixmap)
hbox.addWidget(lbl)
self.setLayout(hbox)
self.setGeometry(300, 300, 280, 170)
self.setWindowTitle('Da window Title')
self.show()
def main():
app = QtGui.QApplication(sys.argv)
ex = Example()
sys.exit(app.exec_())
if __name__ == '__main__':
main()
1 个回答
0
我测试了你提供的简单例子。你可以不使用smc模块,而是直接创建一个新的QPixmap对象,并把*.nef文件的路径作为构造函数的参数传进去。
pixmap = QtGui.QPixmap("Path_To_File.NEF")
lbl = QtGui.QLabel(self)
lbl.setPixmap(pixmap)
我测试了你的例子,运行得很顺利,没有任何问题。