I am new to both Python and WxWindows, but not to programming.
I want to display an image that resides in RAM and not on disk.
My image is an array of RGB tuples with 8 bits per pixel.
My main computer is WinNT 2000, but I desire a cross-platform solution.
My first baby step was the following:
image = wxImage("winnt.bmp", wxBITMAP_TYPE_BMP, -1)
bitmap = wxBitmap(image, -1)
I get the following error:
Traceback (most recent call last):
File "vras.py", line 73, in ?
main()
File "vras.py", line 70, in main
app = MyApp(0)
File "C:\Python22\Lib\site-packages\wxPython\wx.py", line 1808, in
__init__
_wxStart(self.OnInit)
File "vras.py", line 66, in OnInit
frame.runTest(frame, None, None)
File "vras.py", line 51, in runTest
style = wxDEFAULT_FRAME_STYLE)# | wxFRAME_TOOL_WINDOW )
File "vras.py", line 36, in __init__
bitmap = wxBitmap(image, -1)
File "C:\Python22\Lib\site-packages\wxPython\gdi.py", line 122, in
__init__
self.this = apply(gdic.new_wxBitmap,_args,_kwargs)
TypeError: String or Unicode type required
Exception exceptions.AttributeError: "wxBitmap instance has no attribute
'thisown'" in ignored
17:45:11: Debug: e:\projects\wx\src\msw\app.cpp(439):
'UnregisterClass(canvas)' failed with error 0x
00000584 (class still has open windows.).
17:45:11: Debug: e:\projects\wx\src\msw\app.cpp(446): 'UnregisterClass(no
redraw canvas)' failed wit
h error 0x00000584 (class still has open windows.).
I don't know if there simply isn't a binding to this particular wxBitmap
constructor, or
if I have simply coded something incorrectly.
How would I go about determining if the binding is present?
What I really want to do is the following:
#build image in PPM format
#Is there a better way of building the image than this?
magicNumber = "P6"
width = 3
height = 3
maxColorVal = 255
imageHdr = "%s %d %d %d " % (magicNumber, width, height, maxColorVal)
imageData = chr(255)+chr(255)+chr(255) + chr(000)+chr(000)+chr(000) +
chr(255)+chr(255)+chr(255)
imageData += chr(000)+chr(000)+chr(000) + chr(255)+chr(000)+chr(000) +
chr(000)+chr(000)+chr(000)
imageData += chr(255)+chr(255)+chr(255) + chr(000)+chr(000)+chr(000) +
chr(255)+chr(255)+chr(255)
imageBuf = imageHdr + imageData
#somehow construct wxImage from this data without saving it to file first.
···
#
# The following will read from a stream, but can that be a memory buffer?
image = wxImage(stream, wxBITMAP_TYPE_PNM, -1)
bitmap = wxBitmap(image, -1)
wxStaticBitmap(self, -1, bitmap, (0,0))
The other promising function call is
wxImage(int width, int height, unsigned char* data, bool static_data=FALSE)
I get an error calling this function also.
I am not sure if a binding is present for this call.
I also get an error simplying calling
wxImage(3, 3) #binding present?
Thanks,
Jeff