[wxPython] Problem with wxBitmapFromData ()

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

[wxPython] Problem with wxBitmapFromData ()

Mario Tola
Hi,
I'm new to the mailing list an to wxPython. Great work !!!
And now my problem:
I'm traing to create a new wxBitmap object to add to a toolbar. I need to
create it from a window bmp image stored inside a zip file. So I'm using the
zipfile.py module to read the image content from the zip file into a
variable named 'data'.
Then I call:
    bmp = wxBitmapFromData (data, wxBITMAP_TYPE_BMP, 16, 16)
and this is the result:
    'TypeError: wxBitmapFromData, argument 1: expected string without null
bytes, string found'
Also doing this give me the same error:
    f = open ("check.bmp", "rb")
    data = f.read ()
    bmp = wxBitmapFromData (data, wxBITMAP_TYPE_BMP, 16, 16)
Suggestions ?

Thanks in advance.

Mario.





_______________________________________________
wxPython-users maillist  -  [hidden email]
http://starship.python.net/mailman/listinfo/wxpython-users



Reply | Threaded
Open this post in threaded view
|

Re: [wxPython] Problem with wxBitmapFromData ()

Robin Dunn
> I'm traing to create a new wxBitmap object to add to a toolbar. I need to
> create it from a window bmp image stored inside a zip file. So I'm using
the

> zipfile.py module to read the image content from the zip file into a
> variable named 'data'.
> Then I call:
>     bmp = wxBitmapFromData (data, wxBITMAP_TYPE_BMP, 16, 16)
> and this is the result:
>     'TypeError: wxBitmapFromData, argument 1: expected string without null
> bytes, string found'
> Also doing this give me the same error:
>     f = open ("check.bmp", "rb")
>     data = f.read ()
>     bmp = wxBitmapFromData (data, wxBITMAP_TYPE_BMP, 16, 16)
> Suggestions ?
>

Well, I fixed the bug but then it turns out that the BMP handler doesn't
support reading file data from memory like this.  Hopefully this is something
that can be changed in future releases...

The XPM handler will create a wxBitmap from in memory data, but it needs to
be the actual image data, not the XPM file format.

An ugly solution (but easy) would be to write a temporary .bmp file, create
the wxBitmap, and then delete the file.

I intend to wrap wxWindows stream classes such that they can be used with any
Python file-like object.  Once this is done then in memory data of a BMP file
(or other types) will be able to be used to create a wxImage simply by
wrapping a wxPyStream object around a StringIO object.

--
Robin Dunn
Software Craftsman
[hidden email]
http://AllDunn.com/robin/
http://AllDunn.com/wxPython/  Check it out!



_______________________________________________
wxPython-users maillist  -  [hidden email]
http://starship.python.net/mailman/listinfo/wxpython-users