Results 1 to 4 of 4
  1. #1
    Join Date
    Sep 2008
    Posts
    21

    wxAnimation wxAnimationCtrl and GIFs

    Could somebody please give me a short code example on how to display a .gif? While learning wxWidgets in the VTMs I thought it'd be cool to make up some gifs and use them. Apparently it's harder than it looks...I've tried using the documentation included like Joel and Buzz suggest...but it doesn't help me much.

    I've been looking at wxAnimation and wxAnimationCtrl to do this, so I think I'm on the right track. I tried loading the image using:
    Code:
    wxImage animated("animated.gif");
    However when trying to do:
    Code:
    wxAnimation animatedGIF(animated);
    I get: cannot convert parameter 1 from 'wxImage' to 'const wxAnimation &'

    I'm sure it's easy to do, I'm just new at this and I'm trying to figure things out. I like to step away from the VTMs every now and then and try to do things on my own so I get a better understanding of them. What's bothering me is the definition for wxAnimation:

    wxAnimation(const wxAnimation& anim)

    Then the definition for wxBitmap:

    wxBitmap(const wxBitmap& bitmap)

    When using:
    Code:
    wxImage animated("animated.gif");
    wxBitmap testBMP(animated);
    It compiles fine, but doing:
    Code:
    wxImage animated("animated.gif");
    wxAnimation animatedGIF(animated);
    ...gives an error. I figure that after I get this to work somehow, I can then use wxAnimationCtrl to display the GIF.

  2. #2
    Join Date
    Oct 2005
    Location
    Seattle, WA
    Posts
    501
    Code:
    wxAnimation(const wxAnimation& anim)
    This is a copy constructor. As th name suggests, it purpose is to create a new object, wxAnimation in this case, that is the same as another instance of that type. Or more simply, you put one wxAnimation in, and you get 2 wxAnimations out.

    The most likely the error comes from the compiler trying to use the copy constructor because it is the only parameterize constructor for this class. Since the parameters are different the compiler throws an error. To do what you ae trying you would need a constructor that looks like:
    Code:
    wxAnimation(const wxImage& img)
    But, sadly there isn't one.

    After googling wxAnimation, it looks like you need to create a wxAnimation with no parameters. Then call LoadFile().
    Code:
    wxAnimation animatedGif();
    animatedGif.LoadFile(wxString("animated.gif"), WX_ANIMATION_TYPE_GIF);
    Of course, I haven't tried this yet, so some further tweaking might be needed.

  3. #3
    Join Date
    Sep 2008
    Posts
    21
    Code:
    wxAnimation newAni();
    newAni.LoadFile(wxString("greenguy.gif"), wxANIMATION_TYPE_GIF);
    I do this and I get:

    error C2228: left of '.LoadFile' must have class/struct/union

    I've tried solving this portion on my own as well. Googling it mostly resulted in people berating the questioner for not reading the obvious answer stated within the error message. I've done the earlier VTMs (and still going through them to understand them better) but I can't seem to quite get this one.

    I'll keep messing with it and hopefully figure it out eventually.

  4. #4
    Join Date
    Sep 2008
    Posts
    21
    Ok, thanks to doublemax at the wxWidgets forum, this problem is now solved. First of all you have to:

    right click your project - click properties - configuration properties - linker - input - additional dependencies - add wxmsw28d_adv.lib
    This was the first problem. The VTMs only have you add library files that you need for the lessons (seems reasonable)

    Now you can simply add some code to make a default constructor, and load the file:

    Code:
    wxAnimation newAni;
    newAni.LoadFile(_T("greenguy.gif"), wxANIMATION_TYPE_ANY);
    I really hope this helps anyone else who's starting out like I am.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •