0

I've got a wxPython app that uses the following line before creating a wx.BitmapButton:

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

Is there a way to include the image's data in the image, and so something more like this?

plusData = '...√#,›o~ño\Ķ˚fly™Ω.…Õo)Ú∞L∂W_≤Ï~˛⁄...'
imagePlus = wx.Image(plusData, wx.BITMAP_TYPE_PNG).ConvertToBitmap()
2
  • Could you clarify "Is there a way to include the image's data in the image" please? At a guess I would say you want imagePlus = open('wxPlus.png') (or, better, with open('wxPlus.png') as imagePlus:) Commented Oct 26, 2012 at 11:43
  • No, I want to use x = wx.Image() with data stored in a variable (as in with open() as x) instead of a file path Commented Oct 26, 2012 at 13:07

2 Answers 2

1

By using the module StringIO you can create a 'file-like object' that you can pass to wx.ImageFromStream.

import StringIO

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

image = wx.ImageFromStream(stream)
Sign up to request clarification or add additional context in comments.

2 Comments

No. wx.Image(...) requires a path, not an IO object. wxpython.org/docs/api/wx.Image-class.html#__init__
1. docs.wxwidgets.org/stable/wx_wximage.html#wximage - wx.Image can take an InputStream as an argument but maybe not in wxPython. However: 2. I used wx.ImageFromStream - wxpython.org/docs/api/wx-module.html#ImageFromStream
1

If you're using wxPython, I think img2py would be worth a look.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.