+ dc.DrawBitmap( m_bitmap, 0, 0, TRUE /* use mask */ );
+ }
+
+ void OnSave(wxMouseEvent& WXUNUSED(event))
+ {
+ wxImage image = m_bitmap.ConvertToImage();
+
+ int bppselection = wxGetSingleChoiceIndex(_T("Set BMP BPP"),
+ _T("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 loaded;
+ wxString extension = savefilename.AfterLast('.').Lower();
+
+ if (extension == _T("cur"))
+ {
+ image.Rescale(32,32);
+ image.SetOption(wxIMAGE_OPTION_CUR_HOTSPOT_X, 0);
+ image.SetOption(wxIMAGE_OPTION_CUR_HOTSPOT_Y, 0);
+ // This shows how you can save an image with explicitly
+ // specified image format:
+ loaded = image.SaveFile(savefilename, wxBITMAP_TYPE_CUR);
+ }
+ else
+ {
+ // This one guesses image format from filename extension
+ // (it may fail if the extension is not recognized):
+ loaded = image.SaveFile(savefilename);
+ }
+
+ if ( !loaded )
+ wxMessageBox(_T("No handler for this file type."),
+ _T("File was not saved"),
+ wxOK|wxCENTRE, this);