Displaying an image that resides in RAM and not on disk.

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

Change the second line to :

bitmap = wxBitmapFromImage( image )

-D

···

On Wed, May 07, 2003 at 06:16:40PM -0700, Jeff Britton wrote:

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)

--
If your company is not involved in something called "ISO 9000" you
probably have no idea what it is. If your company _is_ involved in ISO
9000 then you definitely have no idea what it is.
                                (Scott Adams - The Dilbert principle)

http://dman.ddts.net/~dman/

You probably will be interested in wxImageFromStream, see the wxPython demo
under the Using Images tree item; it is not documented in the wxWindows docs
or anywhere else that I know of. You may also want to look at

  http://wiki.wxpython.org/index.cgi/WorkingWithImages

And yes wxImageFromStream should be added to that wiki page, I'm hoping
someone will beat me to it.

ka

···

-----Original Message-----
From: Jeff Britton [mailto:jcb@iteris.com]
Sent: Wednesday, May 07, 2003 6:17 PM
To: wxpython-users@lists.wxwindows.org
Subject: [wxPython-users] Displaying an image that resides in RAM and
not on disk.

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

---------------------------------------------------------------------
To unsubscribe, e-mail: wxPython-users-unsubscribe@lists.wxwindows.org
For additional commands, e-mail: wxPython-users-help@lists.wxwindows.org