将PyQt转换为PIL图像 [英] Convert PyQt to PIL image

查看:167
本文介绍了将PyQt转换为PIL图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在QImage中有一个图像,我想在显示之前在PIL中对其进行处理.虽然ImageQT类使我可以将PIL图像转换为QImage,但似乎没有任何东西可以从QImage转换为PIL图像.

I have an image in a QImage and I want to process it in PIL before I display it. While the ImageQT class lets me convert a PIL Image to a QImage, there doesn't appear to anything to go from a QImage to a PIL Image.

推荐答案

我使用以下代码将其从QImage转换为PIL:

I convert it from QImage to PIL with this code:

img = QImage("/tmp/example.png")
buffer = QBuffer()
buffer.open(QIODevice.ReadWrite)
img.save(buffer, "PNG")

strio = cStringIO.StringIO()
strio.write(buffer.data())
buffer.close()
strio.seek(0)
pil_im = Image.open(strio)

在使其生效之前,我尝试了多种组合方式.

I tried many combinations before getting it to work.

这篇关于将PyQt转换为PIL图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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