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. JPEGHandler uses libjpeg created by IJG
.)
See also
__init__ |
Default constructor. |
CanRead |
Returns True if this handler supports the image format contained in the given stream. |
DoCanRead |
Called to test if this handler can read an image from the given stream. |
DoGetImageCount |
Called to get the number of images available in a multi-image file type, if supported. |
GetAltExtensions |
Returns the other file extensions associated with this handler. |
GetExtension |
Gets the preferred file extension associated with this handler. |
GetImageCount |
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. |
GetMimeType |
Gets the MIME type associated with this handler. |
GetName |
Gets the name of this handler. |
GetType |
Gets the image type associated with this handler. |
LoadFile |
Loads a image from a stream, putting the resulting data into image. |
SaveFile |
Saves a image in the output stream. |
SetAltExtensions |
Sets the alternative file extensions associated with this handler. |
SetExtension |
Sets the preferred file extension associated with this handler. |
SetMimeType |
Sets the handler MIME type. |
SetName |
Sets the handler name. |
SetType |
Sets the bitmap type for the handler. |
AltExtensions |
See GetAltExtensions and SetAltExtensions |
Extension |
See GetExtension and SetExtension |
MimeType |
See GetMimeType and SetMimeType |
Name |
See GetName and SetName |
Type |
See GetType and SetType |
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
).
Parameters: | stream (wx.InputStream) – |
---|---|
Return type: | 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
).
Parameters: | filename (string) – |
---|---|
Return type: | 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
Parameters: | stream (wx.InputStream) – |
---|---|
Return type: | 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
Parameters: | stream (wx.InputStream) – |
---|---|
Return type: | int |
GetAltExtensions
(self)¶Returns the other file extensions associated with this handler.
The preferred extension for this handler is returned by GetExtension
.
Return type: | list of strings |
---|
New in version 2.9.0.
GetExtension
(self)¶Gets the preferred file extension associated with this handler.
Return type: | 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.
Parameters: | 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 ). |
---|---|
Return type: | int |
Returns: | 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.
Return type: | string |
---|
GetName
(self)¶Gets the name of this handler.
Return type: | string |
---|
GetType
(self)¶Gets the image type associated with this handler.
Return type: | wx.BitmapType |
---|
LoadFile
(self, image, stream, verbose=True, index=-1)¶Loads a 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.
Parameters: |
|
---|---|
Return type: | bool |
Returns: |
|
See also
SaveFile
(self, image, stream, verbose=True)¶Saves a image in the output stream.
Parameters: |
|
---|---|
Return type: | bool |
Returns: |
|
See also
SetAltExtensions
(self, extensions)¶Sets the alternative file extensions associated with this handler.
Parameters: | 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.
Parameters: | extension (string) – File extension without leading dot. |
---|
See also
SetMimeType
(self, mimetype)¶Sets the handler MIME type.
Parameters: | mimetype (string) – Handler MIME type. |
---|
SetName
(self, name)¶Sets the handler name.
Parameters: | name (string) – Handler name. |
---|
SetType
(self, type)¶Sets the bitmap type for the handler.
Parameters: | type (BitmapType) – |
---|
The bitmap type.
AltExtensions
¶See GetAltExtensions
and SetAltExtensions
Extension
¶See GetExtension
and SetExtension
MimeType
¶See GetMimeType
and SetMimeType