Chris' wxImage::SaveFile(filename_only) patch

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@14655 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Václav Slavík
2002-03-17 11:35:32 +00:00
parent 4fa0a5b443
commit 45647dcf10
4 changed files with 39 additions and 25 deletions

View File

@@ -118,6 +118,7 @@ All (GUI):
- added wxGetFontFromUser() convenience function
- added EVT_MENU_OPEN and EVT_MENU_CLOSE events
- added Hungarian translations (Janos Vegh)
- added wxImage::SaveFile(filename) method (Chris Elliott)
wxMSW:
@@ -125,7 +126,7 @@ wxMSW:
- refresh the buttons properly when the window is resized (Hans Van Leemputten)
- huge (40*) speed up in wxMask::Create()
- changing wxWindows styles also changes the underlying Windows window style
- wxTreeCtrl supports wxTR_HIDE_ROOT stle (George Policello)
- wxTreeCtrl supports wxTR_HIDE_ROOT style (George Policello)
- fixed flicker in wxTreeCtrl::SetItemXXX()
- fixed redraw problems in dynamically resized wxStaticText
- improvements to wxWindows applications behaviour when the system colours

View File

@@ -187,6 +187,7 @@ public:
virtual bool LoadFile( wxInputStream& stream, const wxString& mimetype, int index = -1 );
#endif
virtual bool SaveFile( const wxString& name ) const;
virtual bool SaveFile( const wxString& name, int type ) const;
virtual bool SaveFile( const wxString& name, const wxString& mimetype ) const;

View File

@@ -183,34 +183,28 @@ public:
delete cmap;
}
bool saved = FALSE;
bool loaded;
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")
{
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);
}
// This shows how you can save an image with explicitly
// specified image format:
loaded = image.SaveFile(savefilename, wxBITMAP_TYPE_CUR);
}
else
wxMessageBox("Unknown file type, see options in file selector.",
"Unknown file type",
{
// This one guesses image format from filename extension
// (it may fail if the extension is not recognized):
loaded = image.SaveFile(savefilename);
}
if ( !loaded )
wxMessageBox("No handler for this file type.",
"File was not saved",
wxOK|wxCENTRE, this);
}

View File

@@ -938,6 +938,24 @@ bool wxImage::LoadFile( const wxString& filename, const wxString& mimetype, int
#endif // wxUSE_STREAMS
}
bool wxImage::SaveFile( const wxString& filename ) const
{
wxString ext = filename.AfterLast('.').Lower();
wxImageHandler * pHandler = FindHandler(ext, -1);
if (pHandler)
{
SaveFile(filename, pHandler->GetType());
return TRUE;
}
wxLogError(_("Can't save image to file '%s': unknown extension."), filename.c_str());
return FALSE;
}
bool wxImage::SaveFile( const wxString& filename, int type ) const
{
#if wxUSE_STREAMS