MyFrame();
void OnAbout( wxCommandEvent &event );
+ void OnNewFrame( wxCommandEvent &event );
void OnQuit( wxCommandEvent &event );
MyCanvas *m_canvas;
DECLARE_EVENT_TABLE()
};
+class MyImageFrame : public wxFrame
+{
+public:
+ MyImageFrame(wxFrame *parent, const wxBitmap& bitmap)
+ : wxFrame(parent, -1, _T("Frame with image"),
+ wxDefaultPosition, wxDefaultSize,
+ wxCAPTION | wxSYSTEM_MENU),
+ m_bitmap(bitmap)
+ {
+ SetClientSize(bitmap.GetWidth(), bitmap.GetHeight());
+ }
+
+ void OnPaint(wxPaintEvent& WXUNUSED(event))
+ {
+ wxPaintDC dc( this );
+ dc.DrawBitmap( m_bitmap, 0, 0 );
+ }
+
+private:
+ wxBitmap m_bitmap;
+
+ DECLARE_EVENT_TABLE()
+};
+
// MyApp
class MyApp: public wxApp
IMPLEMENT_DYNAMIC_CLASS(MyCanvas, wxScrolledWindow)
+BEGIN_EVENT_TABLE(MyImageFrame, wxFrame)
+ EVT_PAINT(MyImageFrame::OnPaint)
+END_EVENT_TABLE()
+
BEGIN_EVENT_TABLE(MyCanvas, wxScrolledWindow)
EVT_PAINT(MyCanvas::OnPaint)
END_EVENT_TABLE()
#if wxUSE_LIBPNG
if ( !image.SaveFile( dir + wxString("test.png"), wxBITMAP_TYPE_PNG ))
wxLogError("Can't save file");
-
+
image.Destroy();
image.LoadFile( dir + wxString("test.png") );
my_square = new wxBitmap( image.ConvertToBitmap() );
-
+
image.Destroy();
if ( !image.LoadFile( dir + wxString("horse.png")) )
const int ID_QUIT = 108;
const int ID_ABOUT = 109;
+const int ID_NEW = 110;
IMPLEMENT_DYNAMIC_CLASS( MyFrame, wxFrame )
BEGIN_EVENT_TABLE(MyFrame,wxFrame)
EVT_MENU (ID_ABOUT, MyFrame::OnAbout)
EVT_MENU (ID_QUIT, MyFrame::OnQuit)
+ EVT_MENU (ID_NEW, MyFrame::OnNewFrame)
END_EVENT_TABLE()
MyFrame::MyFrame()
wxPoint(20,20), wxSize(470,360) )
{
wxMenu *file_menu = new wxMenu();
+ file_menu->Append( ID_NEW, "&Show image...");
+ file_menu->AppendSeparator();
file_menu->Append( ID_ABOUT, "&About...");
+ file_menu->AppendSeparator();
file_menu->Append( ID_QUIT, "E&xit");
wxMenuBar *menu_bar = new wxMenuBar();
"About wxImage Demo", wxICON_INFORMATION | wxOK );
}
+void MyFrame::OnNewFrame( wxCommandEvent &WXUNUSED(event) )
+{
+ wxString filename = wxFileSelector(_T("Select image file"));
+ if ( !filename )
+ return;
+
+ wxImage image;
+ if ( !image.LoadFile(filename) )
+ {
+ wxLogError(_T("Couldn't load image from '%s'."), filename.c_str());
+
+ return;
+ }
+
+ (new MyImageFrame(this, image.ConvertToBitmap()))->Show();
+}
+
//-----------------------------------------------------------------------------
// MyApp
//-----------------------------------------------------------------------------