+class MyImageFrame : public wxFrame
+{
+public:
+ MyImageFrame(wxFrame *parent, const wxBitmap& bitmap)
+ : wxFrame(parent, -1, _T("Double click to save"),
+ 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 );
+ }
+
+ void OnSave(wxCommandEvent& WXUNUSED(event))
+ {
+ wxImage image(m_bitmap);
+
+ int bppselection = wxGetSingleChoiceIndex("Set BMP BPP",
+ "Set BMP BPP",
+ nChoices,
+ bppchoices,
+ this);
+ if ( bppselection == -1 )
+ {
+ // cancelled
+ return;
+ }
+
+ image.SetOption(wxBMP_FORMAT, bppvalues[bppselection]);
+
+ wxString deffilename = bppchoices[bppselection];
+ deffilename.Replace(wxT(" "), wxT("_"));
+ deffilename += wxT(".bmp");
+ wxString savefilename = wxFileSelector( wxT("Save Image"),
+ wxT(""),
+ deffilename,
+ (const wxChar *)NULL,
+ wxT("BMP files (*.bmp)|*.bmp|")
+ wxT("PNG files (*.png)|*.png|")
+ wxT("JPEG files (*.jpg)|*.jpg|")
+ wxT("GIF files (*.gif)|*.gif|")
+ wxT("TIFF files (*.tif)|*.tif|")
+ wxT("PCX files (*.pcx)|*.pcx"),
+ wxSAVE);
+
+ if ( savefilename.empty() )
+ return;
+
+ if ( image.GetOptionInt(wxBMP_FORMAT) == wxBMP_8BPP_PALETTE )
+ {
+ unsigned char *cmap = new unsigned char [256];
+ for ( int i = 0; i < 256; i++ )
+ cmap[i] = i;
+ image.SetPalette(wxPalette(256, cmap, cmap, cmap));
+
+ delete cmap;
+ }
+
+ bool saved = FALSE;
+
+ wxString extension = savefilename.AfterLast('.').Lower();
+
+ if (extension == "bmp")
+ saved=image.SaveFile(savefilename, wxBITMAP_TYPE_BMP);
+ else if (extension == "png")
+ saved=image.SaveFile(savefilename, wxBITMAP_TYPE_PNG);
+ else if (extension == "pcx")
+ saved=image.SaveFile(savefilename, wxBITMAP_TYPE_PCX);
+ else if ((extension == "tif") || (extension == "tiff"))
+ saved=image.SaveFile(savefilename, wxBITMAP_TYPE_TIF);
+ else if (extension == "jpg")
+ saved=image.SaveFile(savefilename, wxBITMAP_TYPE_JPEG);
+ else if (extension == "pnm")
+ saved=image.SaveFile(savefilename, wxBITMAP_TYPE_PNM);
+ else
+ wxMessageBox("Unknown file type, see options in file selector.",
+ "Unknown file type",
+ wxOK|wxCENTRE, this);
+ }
+
+private:
+ wxBitmap m_bitmap;
+
+ DECLARE_EVENT_TABLE()
+};
+