How to tranform png to string and that string to a bitmap in Python 3 , wxPython Phoenix?

Hello everybody!!!

I have this png file saved as string :

> 
> Green_tag='\x89PNG\r\n\x1a\n\x00\x00\x00\rIHDR\x00\x00\x00\x10\x00\x00\x00\x10\x08\x06\x00\x00\x00\x1f\xf3\xffa\x00\x00\x036IDATx\x9cbd \x02X\xaeV\x0e\x16\xe5\x11\xd5\x12\xe3\x10\xb1\xe0c\x172\x12\xe4`\x17\xba\xf2\xf6\xf6\xb1\x95\xae\x07\x1c\x01\x00\x00\x00\xff\xffb!\xa4\xd9{\x83\xd9\x83\x1c\xa3Dy\x11\xde\xff\x0c|\xec\xac\x0c\xff\xfe\xfff\xf8\xff\xff\x17\x83\xe9\x17\t\x87\x1f[~\x1e\x05\x00\x00\x00\xff\xff\xc2k\x80\xc3r\xa3\xbb\xd5\x96E\xf2\xdc\\O\x18\xae\xbc\xb9\xcbp\xe3\xd5+\x06Q>n\x06I>\x0e\x06)\x1e!\x06\x19.Q+\x00\x00\x00\x00\xff\xffb\xc2\xa5\xd9f\xbe\xc1\x93\x16\xa7R\xa5\xbf,\xf7\x18\xce\xbd\xbe\xcd0\xfd\xe0\xa9=\x8b\x8f\x9d\xd0\x9e\xb9\xffT\xe7\x87O\x02\x0c\xff\x98\xd9\x19\xde}\xfc\xfa\x02\x00\x00\x00\xff\xff\xc2j\x80\xd9,\xfd\xbb\x1d^u\xd2\xbf\x98\x1e1<\xfc\xfe\x88\xe1\xfdw&\x86G\xcf^M}P\xf8\xf4\xda\xf3\xb7O\xda~\x7f\xe6c\xf8\xf3\x8f\x85\xe1\xcd\xe7\xaf\xe7\x00\x00\x00\x00\xff\xff\xc2\xf0\x82\xd9$\xe3\'\xfd\xbe5\xd2\xef\x18.0<\xfa\xf8\x98A\x84M\x92A^\x80\x8dAMTi\xd9\xdf\x1a\xc6tan\xe1$}\x05U\x86\x07\x9fN3|\xf8\xf4\xe3$\x00\x00\x00\xff\xffbD\xd6\xac\xd6\xacv\xb7 (H\xe9=\xdbE\x86\xab\xefn2\xf0\xb0\xf22\xfcc``\xe0a\xe1`\x90d\x97e\xe0\xf8\xad\xc0` b\xc4\xc0-\xf4\x99a\xf3\xc5S\x0c\xcb\xb6\x1d\n\x02\x00\x00\x00\xff\xff\x82\x1b\xa0\\\xaf\xf6$/(P\xfa3\xcf5\x86\x9bo\xee0\xf0\xb2\xf0100\xfcg\xf8\xcf\xc0\xc0\xf0\x8f\xe1\x1f\xc3\x9f\x7f?\x19X\x98\xff1\xf0\xf3q3\xfcy+\xce\xb0\x7f\xdf\xf3\x87\xe7+\xcf(\x00\x00\x00\x00\xff\xffbd```P\xacP\xbd\x9b\x1f\x1e\xa8\xf4\x8e\xf7:\xc3\xad\x97w\x19\xf88\xf8\x19\xfe\xff\xfb\x87\xe2\xb5\xff\x0cL\x0c\xdc\xbc\x8c\x0c\x8f\x1e~c8\xbf\xe7\xdb\xd3\x07\xdd\xb7d\x18\x18\x18\x18\x00\x00\x00\x00\xff\xffbQ\xaf\xd5>\x91\x1e\xea\xad\xf4\x86\xe3\x06\xc3\xcd\x97\xf7\x18\xf8X\xf8\x18\xfe\xfcA\xd3\xfc\x9f\x81\x81[\x80\x81\xe1\xe9\xc3\x9f\x0c\x97v\xfe\xba\xf7\xa0\xef\x962L\x0e\x00\x00\x00\xff\xffb\x91\xe2\x175\xff*t\x9f\xe1\xf6\x93{\x0c\xdc\xcc\xfc\x0c\x7f\xfe\xffc```D\xb6\x9a\x81\x9b\x9f\x89\xe1\xc9\xfd\xdf\x0c\x17\xb7\x7f}z\x7f\xd2\red\xc3\x01\x00\x00\x00\xff\xffb\xba}\xe7q\xda\xf2\xf9\x17\x18xy\xf8\x18\xfe\xb1\xfcc\xf8\xfd\x97\x81\xe1\xcf\x7f(\xfe\xc7\xc0\xc0\xc1\xcf\xc4\xf0\xe4\xc1/\x86\x0b\x9b?\xdd\xbb?\xe9\x86\x0cz\xac\x01\x00\x00\x00\xff\xffbd```\x90KQ\xcb\x16Td\x9bb\xe8\xcd\xcb\xf0\xe7\'#\xc3\xdf\xdf\xff\x18\xfe100\xf0\n01<\xbb\xfb\x8b\xe1\xca\xb6/O\x1f\xcd\xc4\xd4\xcc\xc0\xc0\xc0\x00\x00\x00\x00\xff\xff\x82\xbbU6E\xbdXH\x81\xa5\xc7\xc0\x8f\x9f\xe1\xcf\xf7\x7f\x0cl\\L\x0c\xaf\x1f\xfcb\xb8\xb8\xe5\xd3\xbd\xc73o)c\xd3\xcc\xc0\xc0\xc0\x00\x00\x00\x00\xff\xffBI\x07\xb2\xc9\xaa\xd9B\nlS\xcc"\x05\x19\x9e\xdf\xf8\xc9pq\xcb\xc7\xa7\x8fg\xdc\xc2j3\x0c\x00\x00\x00\x00\xff\xff\xc2@r\xe9\xaaiz\xf5Z\xff\x95\xf3\xd5\x0f\x10\xa3\x1e\x00\x00\x00\xff\xff\x03\x00$Z\rp\x8d\x19\xf6\x95\x00\x00\x00\x00IEND\xaeB`\x82'

and this Python 2.5 ( on wxPython 2.9 ) code:

import cStringIO

def My_Bitmap(Text):
    return wx.BitmapFromImage(wx.ImageFromStream(cStringIO.StringIO(Text)))

and in the menu-building code i call My_Bitmap() with the PNG text passed.

Now i am moving this project to Python 3.8.2 and wxpython Phoenix
and while i tried few tricks , nothing seems to work. Is there any simple example
on how to do this with ( or without ) the io module that was introduced in Python 3?

Thank you in advance!

Elias

Try using a Bytes object instead of a String.

Green_tag = b'...'

Use a BytesIO for your stream.

stream = BytesIO(Green_tag)

And now that function overloads are supported, you don’t need to use the old custom names anymore.

bmp = wx.Bitmap(wx.Image(stream))