使用 QPixmap 加载图像 [英] Loading an image using QPixmap
问题描述
我有一个图像文件,如 C:/44637landscapes-2007.jpg
我想使用 PySide 使用 QPixmap
加载这个文件
我尝试如下.
pixmap = QPixmap('C:/44637landscapes-2007.jpg')
但是文档说像 QPixmap(':/xxxxxx.jpeg')
.':'
是什么意思?
如何在 'C:\'
加载图像?
问题在于尝试加载 "JPEG"
.它能够加载 "PNG"
,没有问题.那么,我还需要做什么来加载 "JPEG"
?
谢谢极乐
如果您尝试将 Python 代码构建为可执行文件,这涵盖了 .ico 文件的问题,但过程与 JPEG 相同:PyQt/PySide - 图标显示
如果您在从已安装的解释器运行时遇到问题,那么您的路径变量可能设置不正确,您的 qt.conf(在基本 python 目录中)已被删除/更改,或者您没有 qjpeg4.dll 在它应该在的地方 (
).
我的 qt.conf 看起来像:
[路径]前缀 = C:/Python27/lib/site-packages/PySide二进制文件 = .插件 = 插件翻译 = 翻译
C:/Python27/lib/site-packages/PySide
是我系统 PATH 变量的一部分,并且领先任何 PyQt(或其他 Qt)目录.>
I have an image file , as C:/44637landscapes-2007.jpg
I want to load this file using QPixmap
using PySide
I tried as following .
pixmap = QPixmap('C:/44637landscapes-2007.jpg')
But documentation says like QPixmap(':/xxxxxx.jpeg')
. What does ':'
means ?
How do I load an image at 'C:\'
?
EDIT : The problem was with trying to load "JPEG"
. It was able to load "PNG"
, with no issues. So what else , I need to do to load "JPEG"
?
Thanks Jijoy
If you're trying to build your Python code to an executable this covers the issue for .ico files but the process is the same for JPEG: PyQt/PySide - icon display
If you're having problems when running from your installed interpreter then your path variable probably isn't set correctly, your qt.conf (in the base python dir) has been deleted/changed or you don't have qjpeg4.dll where its supposed to be (<python dir>\Lib\site-packages\PySide\plugins\imageformats
).
My qt.conf looks like:
[Paths]
Prefix = C:/Python27/lib/site-packages/PySide
Binaries = .
Plugins = plugins
Translation = translation
C:/Python27/lib/site-packages/PySide
is part of my system PATH variable and ahead of any PyQt (or other Qt) directories.
这篇关于使用 QPixmap 加载图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!