This is the base class for implementing image file loading/saving, and image creation from data.
It is used within wx.Image and is not normally seen by the application.
If you wish to extend the capabilities of wx.Image, derive a class from wx.ImageHandler and add the handler using wx.Image.AddHandler
in your application initialization.
Note that all ImageHandlers provided by wxWidgets are part of the Core library. For details about the default handlers, please see the section Available image handlers in the wx.Image class documentation.
This software is based in part on the work of the Independent JPEG
Group. (Applies when wxWidgets is linked with JPEG
support. wx.JPEGHandler uses libjpeg created by IJG
.)
wx.GIFHandler, wx.IFFHandler, wx.JPEGHandler, wx.PCXHandler, wx.PNGHandler, wx.PNMHandler, wx.TGAHandler, wx.TIFFHandler, wx.XPMHandler
Default constructor. |
|
Returns |
|
Called to test if this handler can read an image from the given stream. |
|
Called to get the number of images available in a multi-image file type, if supported. |
|
Returns the other file extensions associated with this handler. |
|
Gets the preferred file extension associated with this handler. |
|
If the image file contains more than one image and the image handler is capable of retrieving these individually, this function will return the number of available images. |
|
Gets the MIME type associated with this handler. |
|
Gets the name of this handler. |
|
Gets the image type associated with this handler. |
|
Loads an image from a stream, putting the resulting data into image. |
|
Saves an image in the output stream. |
|
Sets the alternative file extensions associated with this handler. |
|
Sets the preferred file extension associated with this handler. |
|
Sets the handler MIME type. |
|
Sets the handler name. |
|
Sets the bitmap type for the handler. |
See |
|
See |
|
See |
|
wx.
ImageHandler
(Object)¶Possible constructors:
ImageHandler()
This is the base class for implementing image file loading/saving, and image creation from data.
__init__
(self)¶Default constructor.
In your own default constructor, initialise the members m_name, m_extension and m_type.
CanRead
(self, *args, **kw)¶CanRead (self, stream)
Returns True
if this handler supports the image format contained in the given stream.
This function doesn’t modify the current stream position (because it restores the original position before returning; this however requires the stream to be seekable; see wx.StreamBase.IsSeekable
).
stream (wx.InputStream) –
bool
CanRead (self, filename)
Returns True
if this handler supports the image format contained in the file with the given name.
This function doesn’t modify the current stream position (because it restores the original position before returning; this however requires the stream to be seekable; see wx.StreamBase.IsSeekable
).
filename (string) –
bool
DoCanRead
(self, stream)¶Called to test if this handler can read an image from the given stream.
NOTE
: this function is allowed to change the current stream position since CallDoCanRead() will take care of restoring it later
stream (wx.InputStream) –
bool
DoGetImageCount
(self, stream)¶Called to get the number of images available in a multi-image file type, if supported.
NOTE
: this function is allowed to change the current stream position since GetImageCount
will take care of restoring it later
stream (wx.InputStream) –
int
GetAltExtensions
(self)¶Returns the other file extensions associated with this handler.
The preferred extension for this handler is returned by GetExtension
.
list of strings
New in version 2.9.0.
GetExtension
(self)¶Gets the preferred file extension associated with this handler.
string
See also
GetImageCount
(self, stream)¶If the image file contains more than one image and the image handler is capable of retrieving these individually, this function will return the number of available images.
stream (wx.InputStream) – Opened input stream for reading image data. This function doesn’t modify the current stream position (because it restores the original position before returning; this however requires the stream to be seekable; see wx.StreamBase.IsSeekable
).
int
Number of available images. For most image handlers, this is 1 (exceptions are TIFF
and ICO
formats as well as animated GIFs for which this function returns the number of frames in the animation).
GetMimeType
(self)¶Gets the MIME type associated with this handler.
string
GetName
(self)¶Gets the name of this handler.
string
GetType
(self)¶Gets the image type associated with this handler.
LoadFile
(self, image, stream, verbose=True, index=-1)¶Loads an image from a stream, putting the resulting data into image.
If the image file contains more than one image and the image handler is capable of retrieving these individually, index indicates which image to read from the stream.
image (wx.Image) – The image object which is to be affected by this operation.
stream (wx.InputStream) – Opened input stream for reading image data.
verbose (bool) – If set to True
, errors reported by the image handler will produce LogMessages.
index (int) – The index of the image in the file (starting from zero).
bool
True
if the operation succeeded, False
otherwise.
See also
SaveFile
(self, image, stream, verbose=True)¶Saves an image in the output stream.
image (wx.Image) – The image object which is to be affected by this operation.
stream (wx.OutputStream) – Opened output stream for writing the data.
verbose (bool) – If set to True
, errors reported by the image handler will produce LogMessages.
bool
True
if the operation succeeded, False
otherwise.
See also
SetAltExtensions
(self, extensions)¶Sets the alternative file extensions associated with this handler.
extensions (list of strings) – Array of file extensions.
New in version 2.9.0.
See also
SetExtension
(self, extension)¶Sets the preferred file extension associated with this handler.
extension (string) – File extension without leading dot.
See also
SetMimeType
(self, mimetype)¶Sets the handler MIME type.
mimetype (string) – Handler MIME type.
SetName
(self, name)¶Sets the handler name.
name (string) – Handler name.
SetType
(self, type)¶Sets the bitmap type for the handler.
type (BitmapType) – The bitmap type.
AltExtensions
¶See GetAltExtensions
and SetAltExtensions
Extension
¶See GetExtension
and SetExtension
MimeType
¶See GetMimeType
and SetMimeType