Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Loading animated GIFs from resource file in wxWidgets

I am trying to embed an animated GIF image into a wxWidgets C++ program. I am able to load the image from file and display it like so:

wxAnimationCtrl *an = new wxAnimationCtrl(this, wxID_ANY, wxAnimation(wxT("image.gif"), wxANIMATION_TYPE_ANY), wxPoint(150,0));
an->Play();

But I would rather have the GIF image in my resource.rc file, so that it is compiled into the executable. How would I do this?

like image 511
user679417 Avatar asked Jan 23 '26 08:01

user679417


2 Answers

You can try to use wxMSWResources or wxLoadUserResource function, load GIF resource to memory, then obtain wxMemoryInputStream and then use wxAnimation::Load() and pass that input stream to that function

like image 155
T-Rex Avatar answered Jan 26 '26 04:01

T-Rex


m_ani = new wxAnimationCtrl();
const void* data = NULL;
size_t outLen = 0;

// load the icon directory resource
if ( !wxLoadUserResource(&data, &outLen, "ID_WAIT", RT_RCDATA) )
{
    wxLogError(_("Failed to load icons from resource"));
}
else
{
    wxMemoryInputStream stream(data, outLen);
    if (m_ani->Load(stream))  m_ani->Play();
}
like image 36
Андрей Ефимов Avatar answered Jan 26 '26 03:01

Андрей Ефимов