如何在 PyQt 上的窗口上加载位图
我目前有一个 PIL 图像,我想将其显示在 PyQt 窗口上。我知道这一定很容易,但我找不到任何地方可以做到这一点。有人可以帮我解决这个问题吗? 这是我当前拥有的窗口的代码:
import sys
from PyQt4 import QtGui
class Window(QtGui.QWidget):
def __init__(self, parent=None):
QtGui.QWidget.__init__(self, parent)
self.setGeometry(300, 300, 250, 150)
self.setWindowTitle('Window')
app = QtGui.QApplication(sys.argv)
window = Window()
window.show()
sys.exit(app.exec_())
编辑:根据使用 Qt 和 Python 的 Rapid Gui 编程:
根据 PyQt 的文档, QPixmaps 针对屏幕进行了优化 显示(因此它们可以快速绘制), 和 QImages 针对编辑进行了优化 (这就是为什么我们用它们来 保存图像数据)。
我有一个复杂的算法,可以生成我想在窗口上显示的图片。它们的创建速度非常快,因此对于用户来说,它们看起来就像一个动画(每秒可能有 15 个以上、20 个以上)。那么我应该使用 QPixmaps 还是 QImages ?
I currently have a PIL Image that I'd like to display on a PyQt window. I know this must be easy, but I can't find anywhere how to do it. Could anyone give me a hand on this?
Here is the code of the window I currently have:
import sys
from PyQt4 import QtGui
class Window(QtGui.QWidget):
def __init__(self, parent=None):
QtGui.QWidget.__init__(self, parent)
self.setGeometry(300, 300, 250, 150)
self.setWindowTitle('Window')
app = QtGui.QApplication(sys.argv)
window = Window()
window.show()
sys.exit(app.exec_())
Edit: According to Rapid Gui Programming with Qt and Python:
According to PyQt’s documentation,
QPixmaps are optimized for on-screen
display (so they are fast to draw),
and QImages are optimized for editing
(which is why we have used them to
hold the image data).
I have a complex algorithm that will generate pictures I want to show on my window. They will be created pretty fast, so to the user they will look just like an animation (there can be like 15+, 20+ of them per second). Should I then use QPixmaps or QImages?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
尝试这样的事情,你可以使用http://svn.effbot。 org/public/stuff/sandbox/pil/ImageQt.py 将任何 pil 图像转换为 qimage
try something like this, you can use http://svn.effbot.org/public/stuff/sandbox/pil/ImageQt.py to convert any pil image to qimage
关于此讨论,最快的方法是使用 GLPainter 可以充分发挥显卡性能。
Regarging to this discussion, the fastest way would be to use GLPainter in order to benefit of the Graphic Card performance.