\func{}{wxImage}{\param{const wxString\& }{name}, \param{long}{ type = wxBITMAP\_TYPE\_PNG}}
+\func{}{wxImage}{\param{const wxString\& }{name}, \param{const wxString\&}{ mimetype}}
+
Loads an image from a file.
\func{}{wxImage}{\param{wxInputStream\& }{stream}, \param{long}{ type = wxBITMAP\_TYPE\_PNG}}
+\func{}{wxImage}{\param{wxInputStream\& }{stream}, \param{const wxString\&}{ mimetype}}
+
Loads an image from an input stream.
\wxheading{Parameters}
a PNG (portable network graphics) file and a JPEG file is supported on all platforms that
implement wxImage.}
+\docparam{mimetype}{MIME type string (for example 'image/jpeg')}
+
Note : you must call wxImage::AddHandler(new wxJPEGHandler) during application
initialization in order to work with JPEGs.
Finds the handler associated with the given image type.
+\func{static wxImageHandler*}{FindHandlerMime}{\param{const wxString\& }{mimetype}}
+
+Finds the handler associated with the given MIME type.
+
\docparam{name}{The handler name.}
\docparam{extension}{The file extension, such as ``bmp".}
\docparam{imageType}{The image type, such as wxBITMAP\_TYPE\_BMP.}
+\docparam{mimetype}{MIME type.}
+
\wxheading{Return value}
A pointer to the handler if found, NULL otherwise.
\func{bool}{LoadFile}{\param{const wxString\&}{ name}, \param{long}{ type}}
+\func{bool}{LoadFile}{\param{const wxString\&}{ name}, \param{const wxString\&}{ mimetype}}
+
Loads an image from a file.
\func{bool}{LoadFile}{\param{wxInputStream\&}{ stream}, \param{long}{ type}}
+\func{bool}{LoadFile}{\param{wxInputStream\&}{ stream}, \param{const wxString\&}{ mimetype}}
+
Loads an image from an input stream.
\wxheading{Parameters}
The validity of these flags depends on the platform and wxWindows configuration.}
+\docparam{mimetype}{MIME type string (for example 'image/jpeg')}
+
\wxheading{Return value}
TRUE if the operation succeeded, FALSE otherwise.
\func{bool}{SaveFile}{\param{const wxString\& }{name}, \param{int}{ type}}
+\func{bool}{SaveFile}{\param{const wxString\& }{name}, \param{const wxString\&}{ mimetype}}
+
Saves a image in the named file.
\func{bool}{SaveFile}{\param{wxOutputStream\& }{stream}, \param{int}{ type}}
+\func{bool}{SaveFile}{\param{wxOutputStream\& }{stream}, \param{const wxString\&}{ mimetype}}
+
Saves a image in the given stream.
\wxheading{Parameters}
The validity of these flags depends on the platform and wxWindows configuration
as well as user-added handlers.}
+\docparam{mimetype}{MIME type.}
+
\wxheading{Return value}
TRUE if the operation succeeded, FALSE otherwise.
Gets the image type associated with this handler.
+\membersection{wxImageHandler::GetMimeType}
+
+\constfunc{wxString}{GetMimeType}{\void}
+
+Gets the MIME type associated with this handler.
+
\membersection{wxImageHandler::LoadFile}\label{wximagehandlerloadfile}
\func{bool}{LoadFile}{\param{wxImage* }{image}, \param{wxInputStream\&}{ stream}}
\docparam{name}{Handler type.}
+
+\membersection{wxImageHandler::SetMimeType}
+
+\func{void}{SetMimeType}{\param{const wxString\& }{mimetype}}
+
+Sets the handler MIME type.
+
+\wxheading{Parameters}
+
+\docparam{mimename}{Handler MIME type.}
+
inline void SetName(const wxString& name) { m_name = name; }
inline void SetExtension(const wxString& ext) { m_extension = ext; }
inline void SetType(long type) { m_type = type; }
+ inline void SetMimeType(const wxString& type) { m_mime = type; }
inline wxString GetName() const { return m_name; }
inline wxString GetExtension() const { return m_extension; }
inline long GetType() const { return m_type; }
-
+ inline wxString GetMimeType() const { return m_mime; }
+
protected:
wxString m_name;
wxString m_extension;
+ wxString m_mime;
long m_type;
};
m_name = "PNG file";
m_extension = "png";
m_type = wxBITMAP_TYPE_PNG;
+ m_mime = "image/png";
};
#if wxUSE_STREAMS
m_name = "JPEG file";
m_extension = "jpg";
m_type = wxBITMAP_TYPE_JPEG;
+ m_mime = "image/jpeg";
};
virtual bool LoadFile( wxImage *image, wxInputStream& stream );
m_name = "BMP file";
m_extension = "bmp";
m_type = wxBITMAP_TYPE_BMP;
+ m_mime = "image/bmp";
};
#if wxUSE_STREAMS
wxImage( int width, int height );
wxImage( const wxString& name, long type = wxBITMAP_TYPE_PNG );
wxImage( wxInputStream& stream, long type = wxBITMAP_TYPE_PNG );
-
+ wxImage( const wxString& name, const wxString& mimetype );
+ wxImage( wxInputStream& stream, const wxString& mimetype );
+
wxImage( const wxImage& image );
wxImage( const wxImage* image );
unsigned char GetBlue( int x, int y );
virtual bool LoadFile( const wxString& name, long type = wxBITMAP_TYPE_PNG );
+ virtual bool LoadFile( const wxString& name, const wxString& mimetype );
#if wxUSE_STREAMS
virtual bool LoadFile( wxInputStream& stream, long type = wxBITMAP_TYPE_PNG );
+ virtual bool LoadFile( wxInputStream& stream, const wxString& mimetype );
#endif
virtual bool SaveFile( const wxString& name, int type );
+ virtual bool SaveFile( const wxString& name, const wxString& mimetype );
#if wxUSE_STREAMS
virtual bool SaveFile( wxOutputStream& stream, int type );
+ virtual bool SaveFile( wxOutputStream& stream, const wxString& mimetype );
#endif
bool Ok() const;
static wxImageHandler *FindHandler( const wxString& name );
static wxImageHandler *FindHandler( const wxString& extension, long imageType );
static wxImageHandler *FindHandler( long imageType );
-
+ static wxImageHandler *FindHandlerMime( const wxString& mimetype );
+
static void CleanUpHandlers();
static void InitStandardHandlers();
#endif
// _WX_IMAGE_H_
+
LoadFile( name, type );
}
+wxImage::wxImage( const wxString& name, const wxString& mimetype )
+{
+ LoadFile( name, mimetype );
+}
+
#if wxUSE_STREAMS
wxImage::wxImage( wxInputStream& stream, long type )
{
LoadFile( stream, type );
}
+
+wxImage::wxImage( wxInputStream& stream, const wxString& mimetype )
+{
+ LoadFile( stream, mimetype );
+}
#endif // wxUSE_STREAMS
wxImage::wxImage( const wxImage& image )
wxFileInputStream stream(filename);
return LoadFile(stream, type);
}
+
+ else {
+ wxLogError( "Can't load image from file '%s': file does not exist.", filename.c_str() );
+
+ return FALSE;
+ }
+#else // !wxUSE_STREAMS
+ return FALSE;
+#endif // wxUSE_STREAMS
+}
+
+bool wxImage::LoadFile( const wxString& filename, const wxString& mimetype )
+{
+#if wxUSE_STREAMS
+ if (wxFileExists(filename))
+ {
+ wxFileInputStream stream(filename);
+ return LoadFile(stream, mimetype);
+ }
else {
wxLogError( "Can't load image from file '%s': file does not exist.", filename.c_str() );
{
#if wxUSE_STREAMS
wxFileOutputStream stream(filename);
-
+
if ( stream.LastError() == wxStream_NOERROR )
return SaveFile(stream, type);
else
return FALSE;
}
+bool wxImage::SaveFile( const wxString& filename, const wxString& mimetype )
+{
+#if wxUSE_STREAMS
+ wxFileOutputStream stream(filename);
+
+ if ( stream.LastError() == wxStream_NOERROR )
+ return SaveFile(stream, mimetype);
+ else
+#endif // wxUSE_STREAMS
+ return FALSE;
+}
+
#if wxUSE_STREAMS
bool wxImage::LoadFile( wxInputStream& stream, long type )
{
return handler->LoadFile( this, stream );
}
+bool wxImage::LoadFile( wxInputStream& stream, const wxString& mimetype )
+{
+ UnRef();
+
+ m_refData = new wxImageRefData;
+
+ wxImageHandler *handler = FindHandlerMime(mimetype);
+
+ if (handler == NULL)
+ {
+ wxLogWarning( "No image handler for type %s defined.", mimetype.GetData() );
+
+ return FALSE;
+ }
+
+ return handler->LoadFile( this, stream );
+}
+
bool wxImage::SaveFile( wxOutputStream& stream, int type )
{
wxCHECK_MSG( Ok(), FALSE, "invalid image" );
-
+
wxImageHandler *handler = FindHandler(type);
-
+
if (handler == NULL)
{
wxLogWarning( "No image handler for type %d defined.", type );
+
+ return FALSE;
+ }
+
+ return handler->SaveFile( this, stream );
+}
+
+bool wxImage::SaveFile( wxOutputStream& stream, const wxString& mimetype )
+{
+ wxCHECK_MSG( Ok(), FALSE, "invalid image" );
+
+ wxImageHandler *handler = FindHandlerMime(mimetype);
+
+ if (handler == NULL)
+ {
+ wxLogWarning( "No image handler for type %s defined.", mimetype.GetData() );
return FALSE;
}
return NULL;
}
+wxImageHandler *wxImage::FindHandlerMime( const wxString& mimetype )
+{
+ wxNode *node = sm_handlers.First();
+ while (node)
+ {
+ wxImageHandler *handler = (wxImageHandler *)node->Data();
+ if (handler->GetMimeType().IsSameAs(mimetype, FALSE)) return handler;
+ node = node->Next();
+ }
+ return NULL;
+}
+
void wxImage::InitStandardHandlers()
{
AddHandler( new wxBMPHandler );