Debian6.0.3 wxGtk Does Not Display wxBitmap Topic is solved

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
guyanqiu
Knows some wx things
Knows some wx things
Posts: 25
Joined: Sun Jun 13, 2010 2:44 pm

Debian6.0.3 wxGtk Does Not Display wxBitmap

Post by guyanqiu » Mon Dec 12, 2011 2:32 am

Hello ,
I use code::blocks10.05, Debian squeeze 6.0.3 , Install the wxGtk2.8.10 with the Synaptic.
I use the wxSmith, only palce a panel1 and a button1 in a dialog, when push the button , Select a image show on the panel.
But the image just show in a flash.Here is the code:

Code: Select all

void imageDialog::OnButton1Click(wxCommandEvent& event)
{
    wxInitAllImageHandlers();   //Initialize graphic format handlers
    wxString caption = wxT("Select an Image");
    wxString wildcard = wxT("Image(*.jpg;*.png;*.bmp)|*.jpg;*.png;*.bmp|All Files(*.*)|*.*");
    wxString defaultDir=wxT("");
    wxString defaultFileName = wxT("");
    wxFileDialog dialog(this,caption,defaultDir,defaultFileName,wildcard,wxFD_OPEN);
    if( dialog.ShowModal() == wxID_OK)
    {
        wxString FilePath_Name = dialog.GetPath();
        wxImage image(FilePath_Name);
        wxBitmap bitmap(image);
        wxClientDC dc(Panel1);
        dc.DrawBitmap(bitmap,0,0,false);
    }
}
Thanks for your help.

DavidHart
Site Admin
Site Admin
Posts: 3881
Joined: Thu Jan 12, 2006 6:23 pm
Location: IoW, UK

Re: Debian6.0.3 wxGtk Does Not Display wxBitmap

Post by DavidHart » Mon Dec 12, 2011 10:08 am

Hi,

You're painting in a wxClientDC, which works. Soon after, OnPaint() is called, which overwrites what you just displayed.

You need to override the panel's OnPaint() and paint the image there, using a wxPaintDC.

Regards,

David

guyanqiu
Knows some wx things
Knows some wx things
Posts: 25
Joined: Sun Jun 13, 2010 2:44 pm

Re: Debian6.0.3 wxGtk Does Not Display wxBitmap

Post by guyanqiu » Mon Dec 12, 2011 2:56 pm

DavidHart wrote:Hi,

You're painting in a wxClientDC, which works. Soon after, OnPaint() is called, which overwrites what you just displayed.

You need to override the panel's OnPaint() and paint the image there, using a wxPaintDC.

Regards,

David
Thanks very much for your reply.
I use OnPaint() EVT_PAINT
I test the code again, it is working.
Thanks a lot.

Post Reply