I've got a simple 20x20 .jpg file I've been trying to convert with img2py so
that I could use it as an icon in a toolbar. It's not working, though,
producing this error when I try to load it into the toolbar:
File "C:\Python23\Lib\site-packages\wx\gdi.py", line 653, in
BitmapFromImage
val = _gdi.new_BitmapFromImage(*args, **kwargs)
wx.core.PyAssertionError: C++ assertion "wxAssertFailure" failed in
..\..\src\msw\bitmap.cpp(765): invalid image
I've tried converting the image to a .bmp and trying that, but the same
error is produced.
I took a look at the wxPython Wiki and found an example of toolbar code that
uses embedded images. There is a difference between the example code and the
code that img2py generated. In the example the "cPickle.loads" method is
used to load the image, where as my generated code looks like:
def getLightningBoltData():
return zlib.decompress(
'x\xda\xd3\xc8)0\xe4\nV72T\x00!\x05Cu\xae\xc4`u=\x85d\x05\xa7\x9c\xc4\xe4l0O
\ ... etc.
No cPickle methods. I would expect there wouldn't be, but I'm new to this so
I'm very probably missing something.
Any ideas or help would be very appreciated.
···
--------------------------------------------
greg mcclure
third stone media
I've got a simple 20x20 .jpg file I've been trying to convert with img2py so
that I could use it as an icon in a toolbar. It's not working, though,
producing this error when I try to load it into the toolbar:
File "C:\Python23\Lib\site-packages\wx\gdi.py", line 653, in
BitmapFromImage
val = _gdi.new_BitmapFromImage(*args, **kwargs)
wx.core.PyAssertionError: C++ assertion "wxAssertFailure" failed in
..\..\src\msw\bitmap.cpp(765): invalid image
I've tried converting the image to a .bmp and trying that, but the same
error is produced.
Does the image work in the toolbar if you load it directly from the .jpg file instead of using img2py? What about if you use other .jpg files? Does your app call wx.InitAllImageHandlers()?
I took a look at the wxPython Wiki and found an example of toolbar code that
uses embedded images. There is a difference between the example code and the
code that img2py generated. In the example the "cPickle.loads" method is
used to load the image, where as my generated code looks like:
def getLightningBoltData():
return zlib.decompress(
'x\xda\xd3\xc8)0\xe4\nV72T\x00!\x05Cu\xae\xc4`u=\x85d\x05\xa7\x9c\xc4\xe4l0O
\ ... etc.
That's the old format that img2py generated before we had the ability to load images from a memory stream. Now it converts them to png's and encodes that directly.
···
--
Robin Dunn
Software Craftsman http://wxPython.org Java give you jitters? Relax with wxPython!
I've got a simple 20x20 .jpg file I've been trying to convert with img2py
so
that I could use it as an icon in a toolbar. It's not working, though,
producing this error when I try to load it into the toolbar:
File "C:\Python23\Lib\site-packages\wx\gdi.py", line 653, in
BitmapFromImage
val = _gdi.new_BitmapFromImage(*args, **kwargs)
wx.core.PyAssertionError: C++ assertion "wxAssertFailure" failed in
..\..\src\msw\bitmap.cpp(765): invalid image
I've tried converting the image to a .bmp and trying that, but the same
error is produced.
Does the image work in the toolbar if you load it directly from the .jpg
file instead of using img2py? What about if you use other .jpg files?
Does your app call wx.InitAllImageHandlers()?
This works fine. I can work with it this way for now, I s'pose.
I was *not*, in fact, calling wx.InitAllImageHandlers() ... Ooo! As I was
writing this response I decided to give it another go, calling img2py and
embedding the data and there you go, it worked.
Life is good.
I suppose the InitAllImageHandlers method did the trick. Thanks!