+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 );
+ //TRUE for masked images
+ dc.DrawBitmap( m_bitmap, 0, 0, TRUE );
+ }
+
+ 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(wxIMAGE_OPTION_BMP_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|")
+ wxT("ICO files (*.ico)|*.ico|")
+ wxT("CUR files (*.cur)|*.cur"),
+ wxSAVE);
+
+ if ( savefilename.empty() )
+ return;
+
+ if ( image.GetOptionInt(wxIMAGE_OPTION_BMP_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 if (extension == "ico")
+ saved=image.SaveFile(savefilename, wxBITMAP_TYPE_ICO);
+ else if (extension == "cur")
+ {
+ image.Rescale(32,32);
+ image.SetOption(wxIMAGE_OPTION_CUR_HOTSPOT_X, 0);
+ image.SetOption(wxIMAGE_OPTION_CUR_HOTSPOT_Y, 0);
+ saved=image.SaveFile(savefilename, wxBITMAP_TYPE_CUR);
+ }
+ else
+ wxMessageBox("Unknown file type, see options in file selector.",
+ "Unknown file type",
+ wxOK|wxCENTRE, this);
+ }
+
+private:
+ wxBitmap m_bitmap;
+
+ DECLARE_EVENT_TABLE()
+};
+