wxBitmap / wxBitmapPtr confusion

Hi,

I have a class with a member called 'image' which holds a wxBitmap. The
following code

print self.image
print dir(self.image)

results in this output:

<C wxBitmap instance at _c6f578_wxBitmap_p>
['CopyFromCursor', 'CopyFromIcon', 'Destroy', 'GetClassName', 'GetDepth',
'GetHa
ndle', 'GetHeight', 'GetMask', 'GetPalette', 'GetQuality', 'GetSubBitmap',
'GetV
isible', 'GetWidth', 'IsNull', 'LoadFile', 'Ok', 'SaveFile', 'SetDepth',
'SetHan
dle', 'SetHeight', 'SetMask', 'SetMaskColour', 'SetPalette', 'SetQuality',
'SetS
ize', 'SetVisible', 'SetWidth', '__del__', '__doc__', '__init__',
'__module__',
'__repr__', 'this', 'thisown']

Where is my 'ConvertToImage' function? If I try

image = self.image.ConvertToImage()

I get the following error:

    image = self.image.ConvertToImage()
AttributeError: wxBitmapPtr instance has no attribute 'ConvertToImage'

Where does the wxBitmapPtr comes from? How can I convert it to an wxBitmap
and then to wxImage? I think the code worked with an earlier build of
version 2.4 (I have 2.4.0.7 installed and I think I had 2.4.0.3 installed
before this).

regards,
Achim

Achim Domma (ProCoders) wrote:

Where is my 'ConvertToImage' function? If I try

image = self.image.ConvertToImage()

I get the following error:

    image = self.image.ConvertToImage()
AttributeError: wxBitmapPtr instance has no attribute 'ConvertToImage'

You are looking for this:

  image = wxImageFromBitmap(self.image)

Where does the wxBitmapPtr comes from?

It is just an implementation detail that helps with returning objects via SWIG. The wrapped object is still a wxBitmap.

···

--
Robin Dunn
Software Craftsman
http://wxPython.org Java give you jitters? Relax with wxPython!

While we're on the topic, is there a copy constructor for wxBitmap?
e.g.,

  bitmap1 = wxBitmap(...)
  bitmap2 = wxBitmapFromBitmap(bitmap1)

(I'm new to python, so I apologize if this is a newbie language
question.)

···

On Wed, May 14, 2003 at 10:14:21AM -0700, Robin Dunn wrote:

You are looking for this:

image = wxImageFromBitmap(self.image)

--
Brian

Brian Victor wrote:

While we're on the topic, is there a copy constructor for wxBitmap?
e.g.,

  bitmap1 = wxBitmap(...)
  bitmap2 = wxBitmapFromBitmap(bitmap1)

Well, from the wxPython notes in the docs, it looks like this constuctor
hasn't been wrapped for Python. Also, while there is a
wxBitmapFromBits(), there doesn't seem to be a wxBitmap.ToBits().

However, I see two options. One is:

Bitmap2 = Bitmap1.ConvertToImage().ConvertToBitmap()

Which seems a little kludgy.

or:

Bitmap2 = Bitmap1.GetSubBitmap((0,0,Bitmap1.GetWidth,Bitmap1.GetHeight))
or maybe:
Bitmap2 =
Bitmap1.GetSubBitmap(wxRect(0,0,Bitmap1.GetWidth,Bitmap1.GetHeight))

Which might be a little more efficient.

I haven't tried either of these, but I'm sure some variation of them
will work.

-Chris

···

--
Christopher Barker, Ph.D.
Oceanographer
                                        
NOAA/OR&R/HAZMAT (206) 526-6959 voice
7600 Sand Point Way NE (206) 526-6329 fax
Seattle, WA 98115 (206) 526-6317 main reception

Chris.Barker@noaa.gov

Brian Victor wrote:

You are looking for this:

image = wxImageFromBitmap(self.image)

While we're on the topic, is there a copy constructor for wxBitmap?
e.g.,

  bitmap1 = wxBitmap(...)
  bitmap2 = wxBitmapFromBitmap(bitmap1)

No, there isn't anything like that. The C++ wxBitmap is reference counted internally so even if I had exposed the copy ctor you would still get just a new refrence to the same bitmap object. If you really need to create a completly new bitmap then are a couple ways to do it. You can either convert to a wxImage and then back to bitmap again, or create the new bitmap with wxEmptyBitmap(w, h) and then select it into a wxMemoryDC and draw the original bitmap to that DC.

(I'm new to python, so I apologize if this is a newbie language
question.)

Everybody was new at one point, so we are usually understanding about growing pains.

···

On Wed, May 14, 2003 at 10:14:21AM -0700, Robin Dunn wrote:

--
Robin Dunn
Software Craftsman
http://wxPython.org Java give you jitters? Relax with wxPython!