wx.ImageList question

I would like to load image from a directory right into an image list.
I wrote a simple library that loads the images in the directory and
resizes them as needed before adding to the wx.ImageList.
This is not the same code but some snippets.

I resize the image this way (using Python Imaging Library):

def resizeimage(image,newsize):
    oldsize = (image.GetWidth(),image.GetHeight())
    if oldsize != newsize:
        return piltoimage(resizepil(imagetopil(image),newsize))
    else:
        return image

This is how I convert images to a bitmaps:

bmp = wx.BitmapFromImage(image,depth=depth)

I have a directory with 16x16 bmp images in it. Everything works fine for sizes
16x16 and below. When I try to use a bigger size (say, 32x32) I get the following
message:

Couldn't add an image to the image list.

It is repeated for every image. There is the same problem when I try to force 8bit color depth.
Where is the problem? Is this related to my Windows XP platform?

Best,

   Laci 2.0

p.s.: I wonder why it is not named wx.BitmapList since one can only store wx.Bitmap instances in it. Late sorrow. :slight_smile:

Laszlo Zsolt Nagy wrote:

I have a directory with 16x16 bmp images in it. Everything works fine for sizes
16x16 and below. When I try to use a bigger size (say, 32x32) I get the following
message:

Couldn't add an image to the image list.

It is repeated for every image. There is the same problem when I try to force 8bit color depth.
Where is the problem? Is this related to my Windows XP platform?

I don't know. Please send me the image files and a sample program that shows the problem and I'll trace it in the debugger.

p.s.: I wonder why it is not named wx.BitmapList since one can only store wx.Bitmap instances in it. Late sorrow. :slight_smile:

Because on Windows it's just a wraper around the Win32 ImageList object.

···

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

Create an empty bitmap, select it into a wx.MemoryDC, have the image list draw the desired image to that dc, and then you have a copy of the bitmap.

I read the docs and I have a dumb question about MemoryDC. This is from the docs:

···

---

A bitmap must be selected into the new memory DC before it may be used for anything. Typical usage is as follows:

  // Create a memory DC
  wxMemoryDC temp_dc;
  temp_dc.SelectObject(test_bitmap);

  // We can now draw into the memory DC...
  // Copy from this DC to another DC.
  old_dc.Blit(250, 50, BITMAP_WIDTH, BITMAP_HEIGHT, temp_dc, 0, 0);

Note that the memory DC /must/ be deleted (or the bitmap selected out of it) before a bitmap can be reselected into another memory DC.
---

How do I delete a DC from Python (this is an object, its descruction is not explicit.)
How do I select out? There is not method to 'select out'. What is it anyway?
I was experimenting with this:

def copybitmap(bmp):
    """Return a copy of a bitmap.
       @param bmp: a wx.Bitmap instance
    @return a copy of the parameter."""
    width,height,depth = bmp.GetWidth(), bmp.GetHeight(), bmp.GetDepth()
    res = wx.EmptyBitmap(width,height,depth)
    new_dc = wx.MemoryDC()
    old_dc = wx.MemoryDC()
    new_dc.SelectObject(res)
    old_dc.SelectObject(bmp)
    try:
        new_dc.Blit(0,0,width,height,old_dc,0,0,useMask=True)
    finally:
        del new_dc # Is this enough for the DC to be destroyed?
        del old_dc # Is this enough for the DC to be destroyed?
    return res