wx.Image: Couldn't add an image to the image list.

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Laszlo Zsolt Nagy

    wx.Image: Couldn't add an image to the image list.

    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(ima ge,newsize):
    oldsize = (image.GetWidth (),image.GetHei ght())
    if oldsize != newsize:
    return piltoimage(resi zepil(imagetopi l(image),newsiz e))
    else:
    return image

    This is how I convert images to a bitmaps:

    bmp = wx.BitmapFromIm age(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. (I used wx.PySimpleApp. ) 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. :-)


  • Kartic

    #2
    Re: wx.Image: Couldn't add an image to the image list.

    Laszlo,

    If you are using PIL just for scaling, you can do away with PIL. Even
    if you do other things with PIL, you can use the Rescale method of the
    wx.Image instance to resize. Here is the code (adapted from the Demo):

    data = open('C:/TEMP/test.bmp'), "rb").read( )
    stream = cStringIO.Strin gIO(data)
    img = wx.ImageFromStr eam( stream )
    img.Rescale(32, 32) # Resize your image to 32x32
    bmp = wx.BitmapFromIm age( img ) # Convert Image to Bitmap
    # Now display Bitmap in Panel
    wx.StaticBitmap (self, -1, bmp, (bmp.GetWidth() , bmp.GetHeight() ))
    Try this and see if this works for you.

    Thank you,
    --Kartic

    Comment

    Working...