2012-10-26 50 views
0

我有一个使用下面的行创建wx.BitmapButton之前的wxPython应用程序:添加图像到python脚本?

imagePlus = wx.Image('wxPlus.png', wx.BITMAP_TYPE_PNG).ConvertToBitmap() 

有没有一种办法,包括图像中的图像数据,所以更多的东西一样吗?

plusData = '...√#,›o~ño\Ķ˚fly™Ω.…Õo)Ú∞L∂W_≤Ï~˛⁄...' 
imagePlus = wx.Image(plusData, wx.BITMAP_TYPE_PNG).ConvertToBitmap() 
+0

请问您能澄清一下“有没有办法将图像的数据包含在图像中”?在猜测中,我会说你想要'imagePlus = open('wxPlus.png')'(或者更好,'open('wxPlus.png')作为imagePlus:') –

+0

不,我想用'x = wx.Image()'将数据存储在一个变量中(例如'with open()as x'),而不是文件路径 – tkbx

回答

1

通过使用StringIO的,你可以创建一个“类文件对象”,你可以传递给wx.ImageFromStream模块。

import StringIO 

stream = StringIO.StringIO() 
stream.write('...√#,›o~ño\Ķ˚fly™Ω.…Õo)Ú∞L∂W_≤Ï~˛⁄...') 

image = wx.ImageFromStream(stream) 
+0

编号wx.Image(...)需要一个路径,而不是IO对象。 http://www.wxpython.org/docs/api/wx.Image-class.html#__init__ –

+0

1. http://docs.wxwidgets.org/stable/wx_wximage.html#wximage - wx.Image可以采取InputStream作为参数,但可能不在wxPython中。但是: 2.我用wx.ImageFromStream - http://www.wxpython.org/docs/api/wx-module.html#ImageFromStream – user1773242

1

如果您使用wxPython,我认为img2py值得一看。