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

Discussion in 'Python' started by Laszlo Zsolt Nagy, Jan 26, 2005.

  1. 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. (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. :)
     
    Laszlo Zsolt Nagy, Jan 26, 2005
    #1
    1. Advertising

  2. Laszlo Zsolt Nagy

    Kartic Guest

    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.StringIO(data)
    img = wx.ImageFromStream( stream )
    img.Rescale(32, 32) # Resize your image to 32x32
    bmp = wx.BitmapFromImage( 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
     
    Kartic, Jan 26, 2005
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. =?Utf-8?B?RW1pbCBHZW9yZ2lldg==?=
    Replies:
    0
    Views:
    489
    =?Utf-8?B?RW1pbCBHZW9yZ2lldg==?=
    May 16, 2004
  2. Bill Reid
    Replies:
    11
    Views:
    473
    Bill Reid
    May 31, 2008
  3. defn noob
    Replies:
    2
    Views:
    858
    Eric Brunel
    Jun 30, 2008
  4. Martin P. Hellwig
    Replies:
    2
    Views:
    1,264
    Martin P. Hellwig
    Dec 9, 2009
  5. Alex SFT
    Replies:
    0
    Views:
    129
    Alex SFT
    Jul 9, 2003
Loading...

Share This Page