Loading A wxAnimationControl With A String

If you are using the main C++ distribution of wxWidgets, Feel free to ask any question related to wxWidgets development here. This means questions regarding to C++ and wxWidgets, not compile problems.
Post Reply
Everydaydiesel
Earned some good credits
Earned some good credits
Posts: 125
Joined: Wed Oct 28, 2015 9:48 pm

Loading A wxAnimationControl With A String

Post by Everydaydiesel »

Hello,

I have an two network applications the 'server' take an image (gif) and transmits that image over the network connection as a string.

Basically I have a string that contains the gif information and I want to load that into a wxAnimationControl.

m_sRawMapData is the string containing the gif data
AnimationCtrl1 is the control to display that data

I am trying to use the Load function of the wxAnimationCtrl which takes a wxInputStream
http://docs.wxwidgets.org/3.1/classwx_a ... 21a59eb634

I have tried several things but I dont seem to understand how to use a wxInputStream

Code: Select all

    wxInputStream is(wxString(m_sRawMapData));
    //is.Read(m_sRawMapData.c_str(), m_sRawMapData.size());
    AnimationCtrl1->Load(is, wxANIMATION_TYPE_GIF);
    AnimationCtrl1->Play();

I also tried searching but could not find an example of going to a string to a wxInputStream.

Thanks in advance
User avatar
doublemax
Moderator
Moderator
Posts: 19160
Joined: Fri Apr 21, 2006 8:03 pm
Location: $FCE2

Re: Loading A wxAnimationControl With A String

Post by doublemax »

The string contains the un-encoded 8bit-data?

Then use wxMemoryInputStream:
http://docs.wxwidgets.org/trunk/classwx ... tream.html
You need to know the exact length of the data, as it could contain 0-bytes.
Use the source, Luke!
Everydaydiesel
Earned some good credits
Earned some good credits
Posts: 125
Joined: Wed Oct 28, 2015 9:48 pm

Re: Loading A wxAnimationControl With A String

Post by Everydaydiesel »

thank you for helping me.

in the example you posted they delete the char array
there is no need for me to do that since i am using a std::string right?

wxMemoryInputStream stream(m_sRawMapData.c_str(), m_sRawMapData.size());
AnimationCtrl1->Load(stream, wxANIMATION_TYPE_GIF);
AnimationCtrl1->Play();
User avatar
doublemax
Moderator
Moderator
Posts: 19160
Joined: Fri Apr 21, 2006 8:03 pm
Location: $FCE2

Re: Loading A wxAnimationControl With A String

Post by doublemax »

there is no need for me to do that since i am using a std::string right?
Yes.

If it doesn't work, save the content of the string to disk and make sure that it contains what you expect. Sending binary data as a string is a little unreliable.
Use the source, Luke!
Everydaydiesel
Earned some good credits
Earned some good credits
Posts: 125
Joined: Wed Oct 28, 2015 9:48 pm

Re: Loading A wxAnimationControl With A String

Post by Everydaydiesel »

Hello,

I am now trying to do this through a wxPaintDC DrawBitmap but it draws the background as hot pink? The gif contains a transparent background.

The commented code is stuff I have tried but doesnt seem to make any difference.

Code: Select all

    
    wxPaintDC dc(pnIcon);
    // dc.SetBrush(colBackground);
    // dc.SetPen( wxPen( wxColor(0,0,0), 1 ) );
    // dc.Clear();
    // dc.SetBackground(wxBrush(wxColor(0,0,0)));
    wxMemoryInputStream stream(m_sRawGifData.c_str(), m_sRawGifData.size());
    wxImage bmp;
    bmp.LoadFile(stream, wxBITMAP_TYPE_GIF);
    dc.DrawBitmap(bmp, 0 , 0);
This is the image (transparent background)
i_c_k_nt_fog.gif
i_c_k_nt_fog.gif (1.8 KiB) Viewed 922 times
User avatar
doublemax
Moderator
Moderator
Posts: 19160
Joined: Fri Apr 21, 2006 8:03 pm
Location: $FCE2

Re: Loading A wxAnimationControl With A String

Post by doublemax »

The DrawBitmap call has a "useMask" parameter, set it to true.
Use the source, Luke!
Post Reply