PyQt4 jpeg/jpg不支持的图像格式 [英] PyQt4 jpeg/jpg unsupported image format

查看:91
本文介绍了PyQt4 jpeg/jpg不支持的图像格式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试获取QImage(或PyQt4中的任何内容)以在脚本中加载jpg文件.我还没有找到任何有关如何获取它作为脚本加载jpg图像的信息,很多可以使用py2exe进行编译,但我什至无法做到.

I'm trying to get QImage (or anything in PyQt4, for that matter) to load a jpg file in a script. I haven't been able to find any information on how to get it to load a jpg image as a script, lots for compiled using py2exe but I can't even get that far.

花一些时间来解决这个问题,我已经关注了一些没有可用的东西.在我的site-packages/PyQt4/plugins/imageformats文件夹中查找:

Spending some time to resolve this, I've followed a few things with no available. Looking in my site-packages/PyQt4/plugins/imageformats folder I have:

qgif4.dll, qico4.dll,qjpeg4.dll, qmng4.dll, qsvg4.dll, qtga4.dll, qtiff4.dll

根据QtGui.QImageReader.supportedImageFormats(),这是我安装的pyqt4可以使用的

According to QtGui.QImageReader.supportedImageFormats(), this is what my install of pyqt4 can use

[PyQt4.QtCore.QByteArray('bmp'), PyQt4.QtCore.QByteArray('pbm'), PyQt4.QtCore.QByteArray('pgm'), PyQt4.QtCore.QByteArray('png'), PyQt4.QtCore.QByteArray('ppm'), PyQt4.QtCore.QByteArray('xbm'), PyQt4.QtCore.QByteArray('xpm')]

我还确保了我的qt.conf文件位于主python目录中,并且具有此文件

I've also made sure that my qt.conf file is in the main python directory and it has this

[路径]

Prefix = C:/Python27/Lib/site-packages/PyQt4
Binaries = C:/Python27/Lib/site-packages/PyQt4

我尝试添加

Plugins = C:/Python27/Lib/site-packages/PyQt4/plugins/imageformats
Plugins = C:/Python27/Lib/site-packages/PyQt4/plugins

没有运气

我正在Windows 7 64b Home Premium上运行带有PyQt4 4.9.1(均为32b)的python 2.7.2.

I'm running python 2.7.2, with PyQt4 4.9.1(both 32b), on a windows 7 64b Home Premium.

我也尝试过4.8.1和4.8.5版本(我手头有),但是它们都不支持jpg.我很茫然.如何获得这些支持?

I've also tried version 4.8.1 and 4.8.5 (which I had on hand) but none of them supported jpg either. I'm at a loss. How do I get these back to being supported?

推荐答案

似乎有两个不同的问题可能导致了这一问题.好像我碰到了两者.

There are two different issues it seems that can contribute to causing this. And it looks like I ran into both.

1st.我以以管理员身份"运行PyQt4安装程序,这似乎已解决了部分问题.因此,它需要以管理员身份运行才能使一切正常工作.

1st. I gave running the PyQt4 installer 'as administrator' which seems to have solved part of the issue. So it needs to be run as administrator to get everything to work correctly.

第二.为了正确加载所有插件,必须先加载QApplication,然后再加载任何类型的图像.

2nd. In order for all the plugins to load properly, the QApplication must be made first before any kind of image is loaded.

如此

app = QtGui.QApplication(sys.argv)

需要首先创建.

我的脚本运行为

def main():
    app = QtGui.QApplication(sys.argv)
    win = window()
    win.display()
    sys.exit(app.exec_())

if __name__ == '__main__':
    main()

自从我以管理员身份安装PyQt4以来并没有改变,但是现在可以正常工作并加载jpeg和其他所有内容.

which hasn't changed since I installed PyQt4 as an administrator but now works and loads jpegs and everything else.

我正在尝试做的是创建一个脚本,该脚本将由PyQt4应用程序调用,但该脚本无法单独运行,因此无需首先创建QApplcation.这是我遇到问题2的地方

What I was trying to do, was create a script that was going to be called by a PyQt4 application but it wouldn't be run by itself, so there was no need to create a QApplcation first. Which is where I ran into issue #2

供参考: http://article. gmane.org/gmane.comp.python.pyqt-pykde/7176/match=jpeg+plugin+not+loading

以管理员身份安装,即使您不需要它也始终创建QApplication.

Install as administrator and always create the QApplication, even if you don't need it.

如果您只是在查看空闲状态下可用的内容,则还可以:

also if you are just checking to see what's available in idle:

from PyQt4 import QtGui
QtGui.QImageReader.supportedImageFormats()

不会显示所有内容,仍然需要运行

won't show everything, still need to run

from PyQt4 import QtGui
import sys
app = QtGui.QApplication(sys.argv)
QtGui.QImageReader.supportedImageFormats()

这很烦人,所以希望对其他人有帮助.

This was annoying to track down, so hopefully this will be helpful to others.

这篇关于PyQt4 jpeg/jpg不支持的图像格式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆