This class encapsulates a platform-independent image.
An image can be created from data, or using wx.Bitmap.ConvertToImage
. An image can be loaded from a file in a variety of formats, and is extensible to new formats via image format handlers. Functions are available to set and get image bits, so it can be used for basic image manipulation.
A wx.Image cannot (currently) be drawn directly to a wx.DC. Instead, a platform-specific wx.Bitmap object must be created from it using the Bitmap.Bitmap(wxImage,int depth) constructor. This bitmap can then be drawn in a device context, using wx.DC.DrawBitmap
.
More on the difference between wx.Image and wx.Bitmap: wx.Image is just a buffer of RGB
bytes with an optional buffer for the alpha bytes. It is all generic, platform independent and image file format independent code. It includes generic code for scaling, resizing, clipping, and other manipulations of the image data. OTOH, wx.Bitmap is intended to be a wrapper of whatever is the native image format that is quickest/easiest to draw to a DC or to be the target of the drawing operations performed on a wx.MemoryDC. By splitting the responsibilities between Image/wxBitmap like this then it’s easier to use generic code shared by all platforms and image types for generic operations and platform specific code where performance or compatibility is needed.
One colour value of the image may be used as a mask colour which will lead to the automatic creation of a wx.Mask object associated to the bitmap object.
Starting from wxWidgets 2.5.0 wx.Image supports alpha channel data, that is in addition to a byte for the red, green and blue colour components for each pixel it also stores a byte representing the pixel opacity. An alpha value of 0 corresponds to a transparent pixel (null opacity) while a value of 255 means that the pixel is 100% opaque. The constants IMAGE_ALPHA_TRANSPARENT
and IMAGE_ALPHA_OPAQUE
can be used to indicate those values in a more readable form. While all images have RGB
data, not all images have an alpha channel. Before using wx.Image.GetAlpha
you should check if this image contains an alpha channel with wx.Image.HasAlpha
. Currently the BMP
, PNG
, TGA
, and TIFF
format handlers have full alpha channel support for loading so if you want to use alpha you have to use one of these formats. If you initialize the image alpha channel yourself using wx.Image.SetAlpha
, you should save it in either PNG
, TGA
, or TIFF
format to avoid losing it as these are the only handlers that currently support saving with alpha.
The following image handlers are available. BMPHandler is always installed by default. To use other image formats, install the appropriate handler with wx.Image.AddHandler
or call wx.InitAllImageHandlers
.
BMPHandler: For loading (including alpha support) and saving, always installed.
wx.PNGHandler: For loading and saving. Includes alpha support.
wx.JPEGHandler: For loading and saving.
wx.GIFHandler: For loading and saving (see below).
wx.PCXHandler: For loading and saving (see below).
wx.PNMHandler: For loading and saving (see below).
wx.TIFFHandler: For loading and saving. Includes alpha support.
wx.TGAHandler: For loading and saving. Includes alpha support.
wx.IFFHandler: For loading only.
wx.XPMHandler: For loading and saving.
ICOHandler: For loading and saving.
CURHandler: For loading and saving.
ANIHandler: For loading only.
When saving in PCX
format, wx.PCXHandler will count the number of different colours in the image; if there are 256 or less colours, it will save as 8 bit, else it will save as 24 bit. Loading PNMs only works for ASCII
or raw RGB
images. When saving in PNM
format, wx.PNMHandler will always save as raw RGB
. Saving GIFs requires images of maximum 8 bpp (see Quantize ), and the alpha channel converted to a mask (see wx.Image.ConvertAlphaToMask
). Saving an animated GIF
requires images of the same size (see wx.GIFHandler.SaveAnimation
)
Creates an empty wx.Image object without an alpha channel. |
|
Register an image handler. |
|
This function muliplies all 4 channels (red, green, blue, alpha) with |
|
Blurs the image in both horizontal and vertical directions by the specified pixel blurRadius. |
|
Blurs the image in the horizontal direction only. |
|
Blurs the image in the vertical direction only. |
|
Returns |
|
Changes the brightness (value) of each pixel in the image. |
|
Changes the hue, the saturation and the brightness (value) of each pixel in the image. |
|
Returns a changed version of the image based on the given lightness. |
|
Changes the saturation of each pixel in the image. |
|
Deletes all image handlers. |
|
Initialize the image data with zeroes (the default) or with the byte value given as value. |
|
Removes the alpha channel from the image. |
|
Computes the histogram of the image. |
|
If the image has alpha channel, this method converts it to mask. |
|
ConvertToBitmap(depth=-1) . Bitmap |
|
Returns disabled (dimmed) version of the image. |
|
Returns a greyscale version of the image. |
|
Returns monochromatic version of the image. |
|
ConvertToMonoBitmap(red, green, blue) . Bitmap |
|
Create a |
|
Returns an identical copy of this image. |
|
Creates a fresh image. |
|
Destroys the image data. |
|
Finds the first colour that is never used in the image. |
|
Finds the handler with the given name. |
|
Finds the handler associated with the given MIME type. |
|
Return alpha value at given pixel location. |
|
Returns a writable Python buffer object that is pointing at the Alpha |
|
Returns the blue intensity at the given coordinate. |
|
Returns a copy of the |
|
Returns a writable Python buffer object that is pointing at the |
|
Returns the currently used default file load flags. |
|
Returns the green intensity at the given coordinate. |
|
Gets the height of the image in pixels. |
|
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. |
|
Iterates all registered wx.ImageHandler objects, and returns a string containing file extension masks suitable for passing to file open/save dialog boxes. |
|
Returns the file load flags used for this object. |
|
Gets the blue value of the mask colour. |
|
Gets the green value of the mask colour. |
|
Gets the red value of the mask colour. |
|
Gets a user-defined string-valued option. |
|
Gets a user-defined integer-valued option. |
|
Get the current mask colour or find a suitable unused colour that could be used as a mask colour. |
|
Returns the palette associated with the image. |
|
Returns the red intensity at the given coordinate. |
|
Returns the size of the image in pixels. |
|
Returns a sub image of the current one as long as the rect belongs entirely to the image. |
|
Gets the type of image found by |
|
Gets the width of the image in pixels. |
|
Converts a color in |
|
Returns |
|
Returns |
|
Returns |
|
Initializes the image alpha channel data. |
|
Internal use only. |
|
Adds a handler at the start of the static list of format handlers. |
|
Returns |
|
Returns |
|
Loads an image from an input stream. |
|
Returns a mirrored copy of the image. |
|
Copy the data of the given image to the specified position in this image. |
|
Converts a color in |
|
Finds the handler with the given name, and removes it. |
|
Replaces the colour specified by r1,g1,b1 by the colour r2,g2,b2. |
|
Changes the size of the image in-place by scaling it: after a call to this function,the image will have the given width and height. |
|
Changes the size of the image in-place without scaling it by adding either a border with the given colour or cropping as necessary. |
|
Rotates the image about the given point, by angle radians. |
|
Returns a copy of the image rotated by 180 degrees. |
|
Returns a copy of the image rotated 90 degrees in the direction indicated by clockwise. |
|
Rotates the hue of each pixel in the image by angle, which is a float in the range [-1.0..+1.0], where -1.0 corresponds to -360 degrees and +1.0 corresponds to +360 degrees. |
|
Saves an image in the given stream. |
|
Returns a scaled version of the image. |
|
Sets the alpha value for the given pixel. |
|
Sets the internal image alpha pointer to point at a Python buffer |
|
Sets the image data without performing checks. |
|
Sets the internal image data pointer to point at a Python buffer |
|
Sets the default value for the flags used for loading image files. |
|
Sets the flags used for loading image files by this object. |
|
Specifies whether there is a mask or not. |
|
Sets the mask colour for this image (and tells the image to use the mask). |
|
Sets image’s mask so that the pixels that have |
|
Sets a user-defined option. |
|
Associates a palette with the image. |
|
Set the color of the pixel at the given x and y coordinate. |
|
Set the type of image returned by |
|
Returns a resized version of this image without scaling it by adding either a border with the given colour or cropping as necessary. |
|
See |
|
See |
|
See |
|
See |
|
See |
wx.
Image
(Object)¶Possible constructors:
Image()
Image(width, height, clear=True)
Image(sz, clear=True)
Image(name, type=BITMAP_TYPE_ANY, index=-1)
Image(name, mimetype, index=-1)
Image(stream, type=BITMAP_TYPE_ANY, index=-1)
Image(stream, mimetype, index=-1)
Image(width, height, data)
Image(width, height, data, alpha)
Image(size, data)
Image(size, data, alpha)
This class encapsulates a platform-independent image.
__init__
(self, *args, **kw)¶__init__ (self)
Creates an empty wx.Image object without an alpha channel.
__init__ (self, width, height, clear=True)
Creates an image with the given size and clears it if requested.
Does not create an alpha channel.
width (int) – Specifies the width of the image.
height (int) – Specifies the height of the image.
clear (bool) – If True
, initialize the image to black.
__init__ (self, sz, clear=True)
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
sz (wx.Size) –
clear (bool) –
__init__ (self, name, type=BITMAP_TYPE_ANY, index=-1)
Creates an image from a file.
name (string) – Name of the file from which to load the image.
type (BitmapType) – May be one of the following:
wx.BITMAP_TYPE_BMP
: Load a Windows bitmap file.
wx.BITMAP_TYPE_GIF
: Load a GIF
bitmap file.
wx.BITMAP_TYPE_JPEG
: Load a JPEG
bitmap file.
wx.BITMAP_TYPE_PNG
: Load a PNG
bitmap file.
wx.BITMAP_TYPE_PCX
: Load a PCX
bitmap file.
wx.BITMAP_TYPE_PNM
: Load a PNM
bitmap file.
wx.BITMAP_TYPE_TIFF
: Load a TIFF
bitmap file.
wx.BITMAP_TYPE_TGA
: Load a TGA
bitmap file.
wx.BITMAP_TYPE_XPM
: Load a XPM bitmap file.
wx.BITMAP_TYPE_ICO
: Load a Windows icon file (ICO
).
wx.BITMAP_TYPE_CUR
: Load a Windows cursor file (CUR
).
wx.BITMAP_TYPE_ANI
: Load a Windows animated cursor file (ANI
).
wx.BITMAP_TYPE_ANY
: Will try to autodetect the format.
index (int) – Index of the image to load in the case that the image file contains multiple images. This is only used by GIF
, ICO
and TIFF
handlers. The default value (-1) means “choose the default image” and is interpreted as the first image (index=0) by the GIF
and TIFF
handler and as the largest and most colourful one by the ICO
handler.
Note
Depending on how wxWidgets has been configured and by which handlers have been loaded, not all formats may be available. Any handler other than BMP
must be previously initialized with wx.Image.AddHandler
or InitAllImageHandlers.
Note
You can use GetOptionInt
to get the hotspot when loading cursor files:
hotspot_x = image.GetOptionInt(wx.IMAGE_OPTION_CUR_HOTSPOT_X)
hotspot_y = image.GetOptionInt(wx.IMAGE_OPTION_CUR_HOTSPOT_Y)
See also
__init__ (self, name, mimetype, index=-1)
Creates an image from a file using MIME-types to specify the type.
name (string) – Name of the file from which to load the image.
mimetype (string) – MIME type string (for example ‘image/jpeg’)
index (int) – See description in wx.Image overload.
__init__ (self, stream, type=BITMAP_TYPE_ANY, index=-1)
Creates an image from a stream.
stream (wx.InputStream) – Opened input stream from which to load the image. Currently, the stream must support seeking.
type (BitmapType) – See description in wx.Image overload.
index (int) – See description in wx.Image overload.
__init__ (self, stream, mimetype, index=-1)
Creates an image from a stream using MIME-types to specify the type.
stream (wx.InputStream) – Opened input stream from which to load the image. Currently, the stream must support seeking.
mimetype (string) – MIME type string (for example ‘image/jpeg’)
index (int) – See description in wx.Image overload.
__init__ (self, width, height, data)
Creates an image from RGB
data in memory.
__init__ (self, width, height, data, alpha)
Creates an image from RGB
data in memory, plus an alpha channel
__init__ (self, size, data)
Creates an image from RGB
data in memory.
__init__ (self, size, data, alpha)
Creates an image from RGB
data in memory, plus an alpha channel
AddHandler
(handler)¶Register an image handler.
Typical example of use:
wx.Image.AddHandler(wx.PNGHandler)
See Available image handlers for a list of the available handlers. You can also use wx.InitAllImageHandlers
to add handlers for all the image formats supported by wxWidgets at once.
handler (wx.ImageHandler) – A heap-allocated handler object which will be deleted by wx.Image if it is removed later by RemoveHandler
or at program shutdown.
AdjustChannels
(self, factor_red, factor_green, factor_blue, factor_alpha=1.0)¶This function muliplies all 4 channels (red, green, blue, alpha) with a factor (around 1.0). Useful for gamma correction, colour correction and to add a certain amount of transparency to a image (fade in fade out effects). If factor_alpha is given but the original image has no alpha channel then a alpha channel will be added.
Blur
(self, blurRadius)¶Blurs the image in both horizontal and vertical directions by the specified pixel blurRadius.
This should not be used when using a single mask colour for transparency.
blurRadius (int) –
See also
BlurHorizontal
(self, blurRadius)¶Blurs the image in the horizontal direction only.
This should not be used when using a single mask colour for transparency.
blurRadius (int) –
See also
BlurVertical
(self, blurRadius)¶Blurs the image in the vertical direction only.
This should not be used when using a single mask colour for transparency.
blurRadius (int) –
See also
CanRead
(*args, **kw)¶CanRead (filename)
Returns True
if at least one of the available image handlers can read the file with the given name.
See wx.ImageHandler.CanRead
for more info.
filename (string) –
bool
CanRead (stream)
Returns True
if at least one of the available image handlers can read the data in the given stream.
See wx.ImageHandler.CanRead
for more info.
stream (wx.InputStream) –
bool
ChangeBrightness
(self, factor)¶Changes the brightness (value) of each pixel in the image.
factor is a float in the range [-1.0..+1.0], where -1.0 corresponds to -100 percent and +1.0 corresponds to +100 percent.
factor (float) –
New in version 4.1/wxWidgets-3.1.6.
ChangeHSV
(self, angleH, factorS, factorV)¶Changes the hue, the saturation and the brightness (value) of each pixel in the image.
angleH is a float in the range [-1.0..+1.0], where -1.0 corresponds to -360 degrees and +1.0 corresponds to +360 degrees, factorS is a float in the range [-1.0..+1.0], where -1.0 corresponds to -100 percent and +1.0 corresponds to +100 percent and factorV is a float in the range [-1.0..+1.0], where -1.0 corresponds to -100 percent and +1.0 corresponds to +100 percent.
angleH (float) –
factorS (float) –
factorV (float) –
New in version 4.1/wxWidgets-3.1.6.
ChangeLightness
(self, alpha)¶Returns a changed version of the image based on the given lightness.
This utility function simply darkens or lightens a color, based on the specified percentage ialpha. ialpha of 0 would make the color completely black, 200 completely white and 100 would not change the color.
alpha (int) –
New in version 4.1/wxWidgets-3.1.6.
Note
This function calls wx.Colour.ChangeLightness
for each pixel in the image.
ChangeSaturation
(self, factor)¶Changes the saturation of each pixel in the image.
factor is a float in the range [-1.0..+1.0], where -1.0 corresponds to -100 percent and +1.0 corresponds to +100 percent.
factor (float) –
New in version 4.1/wxWidgets-3.1.6.
CleanUpHandlers
()¶Deletes all image handlers.
This function is called by wxWidgets on exit.
Clear
(self, value=0)¶Initialize the image data with zeroes (the default) or with the byte value given as value.
value (int) –
New in version 2.9.0.
ClearAlpha
(self)¶Removes the alpha channel from the image.
This function should only be called if the image has alpha channel data, use HasAlpha
to check for this.
New in version 2.9.1.
ComputeHistogram
(self, histogram)¶Computes the histogram of the image.
histogram is a reference to wx.ImageHistogram object. wx.ImageHistogram is a specialization of HashMap “template” and is defined as follows:
# This is a raw translation of the ImageHistogramEntry
# code in C++, not a real Python class
class ImageHistogramEntry(object):
def __init__(self):
self.index = 0
self.value = 0
histogram (wx.ImageHistogram) –
int
Returns number of colours in the histogram.
ConvertAlphaToMask
(self, *args, **kw)¶ConvertAlphaToMask (self, threshold=IMAGE_ALPHA_THRESHOLD)
If the image has alpha channel, this method converts it to mask.
If the image has an alpha channel, all pixels with alpha value less than threshold are replaced with the mask colour and the alpha channel is removed. Otherwise nothing is done.
The mask colour is chosen automatically using FindFirstUnusedColour
, see the overload below if this is not appropriate.
threshold (int) –
bool
Returns True
on success, False
on error.
ConvertAlphaToMask (self, mr, mg, mb, threshold=IMAGE_ALPHA_THRESHOLD)
If the image has alpha channel, this method converts it to mask using the specified colour as the mask colour.
If the image has an alpha channel, all pixels with alpha value less than threshold are replaced with the mask colour and the alpha channel is removed. Otherwise nothing is done.
mr (int) – The red component of the mask colour.
mg (int) – The green component of the mask colour.
mb (int) – The blue component of the mask colour.
threshold (int) – Pixels with alpha channel values below the given threshold are considered to be transparent, i.e. the corresponding mask pixels are set. Pixels with the alpha values above the threshold are considered to be opaque.
bool
Returns True
on success, False
on error.
New in version 2.9.0.
ConvertToDisabled
(self, brightness=255)¶Returns disabled (dimmed) version of the image.
brightness (int) –
New in version 2.9.0.
Note
This function calls wx.Colour.MakeDisabled
for each pixel in the image.
ConvertToGreyscale
(self, *args, **kw)¶ConvertToGreyscale (self, weight_r, weight_g, weight_b)
Returns a greyscale version of the image.
The returned image uses the luminance component of the original to calculate the greyscale. Defaults to using the standard ITU-T
BT.601 when converting to YUV
, where every pixel equals (R weight_r) + (G weight_g) + (B weight_b).
weight_r (float) –
weight_g (float) –
weight_b (float) –
Note
This function calls wx.Colour.MakeGrey
for each pixel in the image.
ConvertToGreyscale (self)
Returns a greyscale version of the image.
New in version 2.9.0.
ConvertToMono
(self, r, g, b)¶Returns monochromatic version of the image.
The returned image has white colour where the original has (r,g,b) colour and black colour everywhere else.
r (int) –
g (int) –
b (int) –
Note
This function calls wx.Colour.MakeMono
for each pixel in the image.
ConvertToMonoBitmap
(self, red, green, blue)¶Creates a monochrome version of the image and returns it as a wx.Bitmap
.
ConvertToRegion
(self, R=-1, G=-1, B=-1, tolerance=0)¶Create a wx.Region
where the transparent areas match the given RGB
values.
If the RGB
values are not given, then the image’s mask colour components will
be used instead. If a non-zero tolerance is given then the pixels that fall
into the range of (R,G,B) to (R+tolerance, G+tolerance, B+tolerance) will be
considered to be transparent.
If there are no pixels matching the transparent colours then the region returned will match the image’s full dimensions.
`R` (int) – The red component of the transparent colour.
`G` (int) – The red component of the transparent colour.
`B` (int) – The red component of the transparent colour.
tolerance (int) – Broadens the range of colours that will be considered transparent.
a wx.Region
object.
Create
(self, *args, **kw)¶Create (self, width, height, clear=True)
Creates a fresh image.
See Image.__init__
for more info.
width (int) –
height (int) –
clear (bool) –
bool
True
if the call succeeded, False
otherwise.
Create (self, sz, clear=True)
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
sz (wx.Size) –
clear (bool) –
bool
Create (self, width, height, data)
Create a new image initialized with the given RGB
data.
bool
Create (self, width, height, data, alpha)
Create a new image initialized with the given RGB
data and Alpha data.
bool
Create (self, size, data)
Create a new image initialized with the given RGB
data.
bool
Create (self, size, data, alpha)
Create a new image initialized with the given RGB
data and Alpha data.
bool
Destroy
(self)¶Destroys the image data.
FindFirstUnusedColour
(self, startR=1, startG=0, startB=0)¶Finds the first colour that is never used in the image.
The search begins at given initial colour and continues by increasing R, G and B components (in this order) by 1 until an unused colour is found or the colour space exhausted.
The parameters r, g, b are pointers to variables to save the colour.
The parameters startR, startG, startB define the initial values of the colour. The returned colour will have RGB
values equal to or greater than these.
startR (int) –
startG (int) –
startB (int) –
tuple
( r, g, b )
Note
This method involves computing the histogram, which is a computationally intensive operation.
FindHandler
(*args, **kw)¶FindHandler (name)
Finds the handler with the given name.
name (string) – The handler name.
A pointer to the handler if found, None
otherwise.
See also
FindHandler (extension, imageType)
Finds the handler associated with the given extension and type.
extension (string) – The file extension, such as “bmp”.
imageType (BitmapType) – The image type; one of the wx.BitmapType values.
A pointer to the handler if found, None
otherwise.
See also
FindHandler (imageType)
Finds the handler associated with the given image type.
imageType (BitmapType) – The image type; one of the wx.BitmapType values.
A pointer to the handler if found, None
otherwise.
FindHandlerMime
(mimetype)¶Finds the handler associated with the given MIME type.
mimetype (string) – MIME type.
A pointer to the handler if found, None
otherwise.
See also
GetAlpha
(self, *args, **kw)¶GetAlpha (self, x, y)
Return alpha value at given pixel location.
x (int) –
y (int) –
int
GetAlpha (self)
Returns a copy of the Alpha bytes of the image.
PyObject
GetAlphaBuffer
(self)¶Returns a writable Python buffer object that is pointing at the Alpha data buffer inside the
Image
. You need to ensure that you do not use this buffer object after the image has been destroyed.
PyObject
GetBlue
(self, x, y)¶Returns the blue intensity at the given coordinate.
x (int) –
y (int) –
int
GetData
(self)¶Returns a copy of the RGB
bytes of the image.
PyObject
GetDataBuffer
(self)¶Returns a writable Python buffer object that is pointing at the
RGB
image data buffer inside theImage
. You need to ensure that you do not use this buffer object after the image has been destroyed.
PyObject
GetDefaultLoadFlags
()¶Returns the currently used default file load flags.
See SetDefaultLoadFlags
for more information about these flags.
int
New in version 4.1/wxWidgets-3.1.0.
GetGreen
(self, x, y)¶Returns the green intensity at the given coordinate.
x (int) –
y (int) –
int
GetHeight
(self)¶Gets the height of the image in pixels.
int
GetImageCount
(*args, **kw)¶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.
For the overload taking the parameter filename, that’s the name of the file to query. For the overload taking the parameter stream, that’s the opened input stream with image data.
See wx.ImageHandler.GetImageCount
for more info.
The parameter type may be one of the following values:
wx.BITMAP_TYPE_BMP
: Load a Windows bitmap file.
wx.BITMAP_TYPE_GIF
: Load a GIF
bitmap file.
wx.BITMAP_TYPE_JPEG
: Load a JPEG
bitmap file.
wx.BITMAP_TYPE_PNG
: Load a PNG
bitmap file.
wx.BITMAP_TYPE_PCX
: Load a PCX
bitmap file.
wx.BITMAP_TYPE_PNM
: Load a PNM
bitmap file.
wx.BITMAP_TYPE_TIFF
: Load a TIFF
bitmap file.
wx.BITMAP_TYPE_TGA
: Load a TGA
bitmap file.
wx.BITMAP_TYPE_XPM
: Load a XPM bitmap file.
wx.BITMAP_TYPE_ICO
: Load a Windows icon file (ICO
).
wx.BITMAP_TYPE_CUR
: Load a Windows cursor file (CUR
).
wx.BITMAP_TYPE_ANI
: Load a Windows animated cursor file (ANI
).
wx.BITMAP_TYPE_ANY
: Will try to autodetect the format.
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).
GetImageCount (filename, type=BITMAP_TYPE_ANY)
filename (string) –
type (BitmapType) –
int
GetImageCount (stream, type=BITMAP_TYPE_ANY)
stream (wx.InputStream) –
type (BitmapType) –
int
GetImageExtWildcard
()¶Iterates all registered wx.ImageHandler objects, and returns a string containing file extension masks suitable for passing to file open/save dialog boxes.
string
The format of the returned string is "(*.ext1;*.ext2)|*.ext1;*.ext2"
. It is usually a good idea to prepend a description before passing the result to the dialog. Example:
FileDlg = wx.FileDialog(self, "Choose Image", os.getcwd(), "",
"Image Files " + wx.Image.GetImageExtWildcard(),
wx.FD_OPEN)
See also
GetLoadFlags
(self)¶Returns the file load flags used for this object.
See SetLoadFlags
for more information about these flags.
int
New in version 4.1/wxWidgets-3.1.0.
GetMaskBlue
(self)¶Gets the blue value of the mask colour.
int
GetMaskGreen
(self)¶Gets the green value of the mask colour.
int
GetMaskRed
(self)¶Gets the red value of the mask colour.
int
GetOption
(self, name)¶Gets a user-defined string-valued option.
Generic options:
IMAGE_OPTION_FILENAME:
The name of the file from which the image was loaded.
Options specific to wx.GIFHandler:
IMAGE_OPTION_GIF_COMMENT:
The comment text that is read from or written to the GIF
file. In an animated GIF
each frame can have its own comment. If there is only a comment in the first frame of a GIF
it will not be repeated in other frames.
name (string) – The name of the option, case-insensitive.
string
The value of the option or an empty string if not found. Use HasOption
if an empty string can be a valid option value.
See also
GetOptionInt
(self, name)¶Gets a user-defined integer-valued option.
The function is case-insensitive to name. If the given option is not present, the function returns 0. Use HasOption
if 0 is a possibly valid value for the option.
Generic options:
IMAGE_OPTION_MAX_WIDTH
and IMAGE_OPTION_MAX_HEIGHT:
If either of these options is specified, the loaded image will be scaled down (preserving its aspect ratio) so that its width is less than the max width given if it is not 0 and its height is less than the max height given if it is not 0. This is typically used for loading thumbnails and the advantage of using these options compared to calling Rescale
after loading is that some handlers (only JPEG
one right now) support rescaling the image during loading which is vastly more efficient than loading the entire huge image and rescaling it later (if these options are not supported by the handler, this is still what happens however). These options must be set before calling LoadFile
to have any effect.
IMAGE_OPTION_ORIGINAL_WIDTH
and IMAGE_OPTION_ORIGINAL_HEIGHT:
These options will return the original size of the image if either IMAGE_OPTION_MAX_WIDTH
or IMAGE_OPTION_MAX_HEIGHT
is specified.
New in version 2.9.3.
IMAGE_OPTION_QUALITY:
JPEG
quality used when saving. This is an integer in 0..100 range with 0 meaning very poor and 100 excellent (but very badly compressed). This option is currently ignored for the other formats.
IMAGE_OPTION_RESOLUTIONUNIT:
The value of this option determines whether the resolution of the image is specified in centimetres or inches, see ImageResolution enum elements.
IMAGE_OPTION_RESOLUTION
, IMAGE_OPTION_RESOLUTIONX
and IMAGE_OPTION_RESOLUTIONY:
These options define the resolution of the image in the units corresponding to IMAGE_OPTION_RESOLUTIONUNIT
options value. The first option can be set before saving the image to set both horizontal and vertical resolution to the same value. The X and Y options are set by the image handlers if they support the image resolution (currently BMP
, JPEG
and TIFF
handlers do) and the image provides the resolution information and can be queried after loading the image.
Options specific to wx.PNGHandler:
IMAGE_OPTION_PNG_FORMAT:
Format for saving a PNG
file, see ImagePNGType for the supported values.
IMAGE_OPTION_PNG_BITDEPTH:
Bit depth for every channel (R/G/B/A).
IMAGE_OPTION_PNG_FILTER:
Filter for saving a PNG
file, see libpng (http://www.libpng.org/pub/png/libpng-1.2.5-manual.html) for possible values (e.g. PNG_FILTER_NONE
, PNG_FILTER_SUB
, PNG_FILTER_UP
, etc).
IMAGE_OPTION_PNG_COMPRESSION_LEVEL:
Compression level (0..9) for saving a PNG
file. A high value creates smaller-but-slower PNG
file. Note that unlike other formats (e.g. JPEG
) the PNG
format is always lossless and thus this compression level doesn’t tradeoff the image quality.
IMAGE_OPTION_PNG_COMPRESSION_MEM_LEVEL:
Compression memory usage level (1..9) for saving a PNG
file. A high value means the saving process consumes more memory, but may create smaller PNG
file.
IMAGE_OPTION_PNG_COMPRESSION_STRATEGY:
Possible values are 0 for default strategy, 1 for filter, and 2 for Huffman-only. You can use OptiPNG (http://optipng.sourceforge.net/) to get a suitable value for your application.
IMAGE_OPTION_PNG_COMPRESSION_BUFFER_SIZE:
Internal buffer size (in bytes) for saving a PNG
file. Ideally this should be as big as the resulting PNG
file. Use this option if your application produces images with small size variation.
Options specific to wx.TIFFHandler:
IMAGE_OPTION_TIFF_BITSPERSAMPLE:
Number of bits per sample (channel). Currently values of 1 and 8 are supported. A value of 1 results in a black and white image. A value of 8 (the default) can mean greyscale or RGB
, depending on the value of IMAGE_OPTION_TIFF_SAMPLESPERPIXEL
.
IMAGE_OPTION_TIFF_SAMPLESPERPIXEL:
Number of samples (channels) per pixel. Currently values of 1 and 3 are supported. A value of 1 results in either a greyscale (by default) or black and white image, depending on the value of IMAGE_OPTION_TIFF_BITSPERSAMPLE
. A value of 3 (the default) will result in an RGB
image.
IMAGE_OPTION_TIFF_COMPRESSION:
Compression type. By default it is set to 1 (COMPRESSION_NONE
). Typical other values are 5 (COMPRESSION_LZW
) and 7 (COMPRESSION_JPEG
). See tiff.h for more options.
IMAGE_OPTION_TIFF_PHOTOMETRIC:
Specifies the photometric interpretation. By default it is set to 2 (PHOTOMETRIC_RGB
) for RGB
images and 0 (PHOTOMETRIC_MINISWHITE
) for greyscale or black and white images. It can also be set to 1 (PHOTOMETRIC_MINISBLACK
) to treat the lowest value as black and highest as white. If you want a greyscale image it is also sufficient to only specify IMAGE_OPTION_TIFF_PHOTOMETRIC
and set it to either PHOTOMETRIC_MINISWHITE
or PHOTOMETRIC_MINISBLACK
. The other values are taken care of.
Options specific to wx.GIFHandler:
IMAGE_OPTION_GIF_TRANSPARENCY:
How to deal with transparent pixels. By default, the color of transparent pixels is changed to bright pink, so that if the image is accidentally drawn without transparency, it will be obvious. Normally, this would not be noticed, as these pixels will not be rendered. But in some cases it might be useful to load a GIF
without making any modifications to its colours. Use IMAGE_OPTION_GIF_TRANSPARENCY_UNCHANGED
to keep the colors correct. Use IMAGE_OPTION_GIF_TRANSPARENCY_HIGHLIGHT
to convert transparent pixels to pink (default). This option has been added in wxWidgets 3.1.1.
name (string) – The name of the option, case-insensitive.
int
The value of the option or 0 if not found. Use HasOption
if 0 can be a valid option value.
Note
Be careful when combining the options IMAGE_OPTION_TIFF_SAMPLESPERPIXEL
, IMAGE_OPTION_TIFF_BITSPERSAMPLE
, and IMAGE_OPTION_TIFF_PHOTOMETRIC
. While some measures are taken to prevent illegal combinations and/or values, it is still easy to abuse them and come up with invalid results in the form of either corrupted images or crashes.
GetOrFindMaskColour
(self)¶Get the current mask colour or find a suitable unused colour that could be used as a mask colour.
Returns True
if the image currently has a mask.
tuple
( r, g, b )
GetPalette
(self)¶Returns the palette associated with the image.
Currently the palette is only used when converting to wx.Bitmap under Windows.
Some of the wx.Image handlers have been modified to set the palette if one exists in the image file (usually 256 or less colour images in GIF
or PNG
format).
GetRed
(self, x, y)¶Returns the red intensity at the given coordinate.
x (int) –
y (int) –
int
GetSubImage
(self, rect)¶Returns a sub image of the current one as long as the rect belongs entirely to the image.
GetType
(self)¶Gets the type of image found by LoadFile
or specified with SaveFile
.
New in version 2.9.0.
GetWidth
(self)¶Gets the width of the image in pixels.
int
HSVtoRGB
(hsv)¶Converts a color in HSV
color space to RGB
color space.
HasAlpha
(self)¶Returns True
if this image has alpha channel, False
otherwise.
bool
HasMask
(self)¶Returns True
if there is a mask active, False
otherwise.
bool
HasOption
(self, name)¶Returns True
if the given option is present.
The function is case-insensitive to name.
The lists of the currently supported options are in GetOption
and GetOptionInt
function docs.
name (string) –
bool
See also
InitAlpha
(self)¶Initializes the image alpha channel data.
It is an error to call it if the image already has alpha data. If it doesn’t, alpha data will be by default initialized to all pixels being fully opaque. But if the image has a mask colour, all mask pixels will be completely transparent.
InitStandardHandlers
()¶Internal use only.
Adds standard image format handlers. It only install BMPHandler for the time being, which is used by wx.Bitmap.
This function is called by wxWidgets on startup, and shouldn’t be called by the user.
See also
wx.ImageHandler, wx.InitAllImageHandlers
, Quantize
InsertHandler
(handler)¶Adds a handler at the start of the static list of format handlers.
handler (wx.ImageHandler) – A new image format handler object. There is usually only one instance of a given handler class in an application session.
See also
IsOk
(self)¶Returns True
if image data is present.
bool
IsTransparent
(self, x, y, threshold=IMAGE_ALPHA_THRESHOLD)¶Returns True
if the given pixel is transparent, i.e. either has the mask colour if this image has a mask or if this image has alpha channel and alpha value of this pixel is strictly less than threshold.
x (int) –
y (int) –
threshold (int) –
bool
LoadFile
(self, *args, **kw)¶LoadFile (self, stream, type=BITMAP_TYPE_ANY, index=-1)
Loads an image from an input stream.
If the file can’t be loaded, this function returns False
and logs an error using wx.LogError
. If the file can be loaded but some problems were detected while doing it, it can also call wx.LogWarning
to notify about these problems. If this is undesirable, use SetLoadFlags
to reset Load_Verbose
flag and suppress these warnings.
stream (wx.InputStream) – Opened input stream from which to load the image. Currently, the stream must support seeking.
type (BitmapType) – May be one of the following:
wx.BITMAP_TYPE_BMP
: Load a Windows bitmap file.
wx.BITMAP_TYPE_GIF
: Load a GIF
bitmap file.
wx.BITMAP_TYPE_JPEG
: Load a JPEG
bitmap file.
wx.BITMAP_TYPE_PNG
: Load a PNG
bitmap file.
wx.BITMAP_TYPE_PCX
: Load a PCX
bitmap file.
wx.BITMAP_TYPE_PNM
: Load a PNM
bitmap file.
wx.BITMAP_TYPE_TIFF
: Load a TIFF
bitmap file.
wx.BITMAP_TYPE_TGA
: Load a TGA
bitmap file.
wx.BITMAP_TYPE_XPM
: Load a XPM bitmap file.
wx.BITMAP_TYPE_ICO
: Load a Windows icon file (ICO
).
wx.BITMAP_TYPE_CUR
: Load a Windows cursor file (CUR
).
wx.BITMAP_TYPE_ANI
: Load a Windows animated cursor file (ANI
).
wx.BITMAP_TYPE_ANY
: Will try to autodetect the format.
index (int) – Index of the image to load in the case that the image file contains multiple images. This is only used by GIF
, ICO
and TIFF
handlers. The default value (-1) means “choose the default image” and is interpreted as the first image (index=0) by the GIF
and TIFF
handler and as the largest and most colourful one by the ICO
handler.
bool
True
if the operation succeeded, False
otherwise. If the optional index parameter is out of range, False
is returned and a call to wx.LogError
takes place.
Note
Depending on how wxWidgets has been configured, not all formats may be available.
Note
You can use GetOptionInt
to get the hotspot when loading cursor files:
hotspot_x = image.GetOptionInt(wx.IMAGE_OPTION_CUR_HOTSPOT_X)
hotspot_y = image.GetOptionInt(wx.IMAGE_OPTION_CUR_HOTSPOT_Y)
See also
LoadFile (self, name, type=BITMAP_TYPE_ANY, index=-1)
Loads an image from a file.
If no handler type is provided, the library will try to autodetect the format.
name (string) – Name of the file from which to load the image.
type (BitmapType) – See the description in the LoadFile
overload.
index (int) – See the description in the LoadFile
overload.
bool
LoadFile (self, name, mimetype, index=-1)
Loads an image from a file.
If no handler type is provided, the library will try to autodetect the format.
name (string) – Name of the file from which to load the image.
mimetype (string) – MIME type string (for example ‘image/jpeg’)
index (int) – See the description in the LoadFile
overload.
bool
LoadFile (self, stream, mimetype, index=-1)
Loads an image from an input stream.
stream (wx.InputStream) – Opened input stream from which to load the image. Currently, the stream must support seeking.
mimetype (string) – MIME type string (for example ‘image/jpeg’)
index (int) – See the description in the LoadFile
overload.
bool
Mirror
(self, horizontally=True)¶Returns a mirrored copy of the image.
The parameter horizontally indicates the orientation.
horizontally (bool) –
Paste
(self, image, x, y, alphaBlend=IMAGE_ALPHA_BLEND_OVER)¶Copy the data of the given image to the specified position in this image.
Takes care of the mask colour and out of bounds problems.
image (wx.Image) – The image containing the data to copy, must be valid.
x (int) – The horizontal position of the position to copy the data to.
y (int) – The vertical position of the position to copy the data to.
alphaBlend (ImageAlphaBlendMode) – This parameter (new in 3.1.5) determines whether the alpha values of the original image replace (default) or are composed with the alpha channel of this image. Notice that alpha blending overrides the mask handling.
RGBtoHSV
(rgb)¶Converts a color in RGB
color space to HSV
color space.
RemoveHandler
(name)¶Finds the handler with the given name, and removes it.
The handler is also deleted.
name (string) – The handler name.
bool
True
if the handler was found and removed, False
otherwise.
See also
Replace
(self, r1, g1, b1, r2, g2, b2)¶Replaces the colour specified by r1,g1,b1 by the colour r2,g2,b2.
r1 (int) –
g1 (int) –
b1 (int) –
r2 (int) –
g2 (int) –
b2 (int) –
Rescale
(self, width, height, quality=IMAGE_QUALITY_NORMAL)¶Changes the size of the image in-place by scaling it: after a call to this function,the image will have the given width and height.
For a description of the quality parameter, see the Scale
function. Returns the (modified) image itself.
width (int) –
height (int) –
quality (ImageResizeQuality) –
See also
Resize
(self, size, pos, red=-1, green=-1, blue=-1)¶Changes the size of the image in-place without scaling it by adding either a border with the given colour or cropping as necessary.
The image is pasted into a new image with the given size and background colour at the position pos relative to the upper left of the new image.
If red = green = blue = -1 then use either the current mask colour if set or find, use, and set a suitable mask colour for any newly exposed areas.
The (modified) image itself.
See also
Rotate
(self, angle, rotationCentre, interpolating=True, offsetAfterRotation=None)¶Rotates the image about the given point, by angle radians.
Passing True
to interpolating results in better image quality, but is slower.
If the image has a mask, then the mask colour is used for the uncovered pixels in the rotated image background. Else, black (rgb 0, 0, 0) will be used.
Returns the rotated image, leaving this image intact.
Rotate180
(self)¶Returns a copy of the image rotated by 180 degrees.
New in version 2.9.2.
Rotate90
(self, clockwise=True)¶Returns a copy of the image rotated 90 degrees in the direction indicated by clockwise.
clockwise (bool) –
RotateHue
(self, angle)¶Rotates the hue of each pixel in the image by angle, which is a float in the range [-1.0..+1.0], where -1.0 corresponds to -360 degrees and +1.0 corresponds to +360 degrees.
angle (float) –
SaveFile
(self, *args, **kw)¶SaveFile (self, stream, mimetype)
Saves an image in the given stream.
stream (wx.OutputStream) – Opened output stream to save the image to.
mimetype (string) – MIME type.
bool
True
if the operation succeeded, False
otherwise.
Note
Depending on how wxWidgets has been configured, not all formats may be available.
Note
You can use SetOption
to set the hotspot when saving an image into a cursor file (default hotspot is in the centre of the image):
image.SetOption(wx.IMAGE_OPTION_CUR_HOTSPOT_X, hotspotX)
image.SetOption(wx.IMAGE_OPTION_CUR_HOTSPOT_Y, hotspotY)
See also
SaveFile (self, name, type)
Saves an image in the named file.
name (string) – Name of the file to save the image to.
type (BitmapType) – Currently these types can be used:
wx.BITMAP_TYPE_BMP
: Save a BMP
image file.
wx.BITMAP_TYPE_JPEG
: Save a JPEG
image file.
wx.BITMAP_TYPE_PNG
: Save a PNG
image file.
wx.BITMAP_TYPE_PCX
: Save a PCX
image file (tries to save as 8-bit if possible, falls back to 24-bit otherwise).
wx.BITMAP_TYPE_PNM
: Save a PNM
image file (as raw RGB
always).
wx.BITMAP_TYPE_TIFF
: Save a TIFF
image file.
wx.BITMAP_TYPE_XPM
: Save a XPM image file.
wx.BITMAP_TYPE_ICO
: Save a Windows icon file (ICO
). The size may be up to 255 wide by 127 high. A single image is saved in 8 colors at the size supplied.
wx.BITMAP_TYPE_CUR
: Save a Windows cursor file (CUR
).
bool
SaveFile (self, name, mimetype)
Saves an image in the named file.
name (string) – Name of the file to save the image to.
mimetype (string) – MIME type.
bool
SaveFile (self, name)
Saves an image in the named file.
File type is determined from the extension of the file name. Note that this function may fail if the extension is not recognized! You can use one of the forms above to save images to files with non-standard extensions.
name (string) – Name of the file to save the image to.
bool
SaveFile (self, stream, type)
Saves an image in the given stream.
stream (wx.OutputStream) – Opened output stream to save the image to.
type (BitmapType) – MIME type.
bool
Scale
(self, width, height, quality=IMAGE_QUALITY_NORMAL)¶Returns a scaled version of the image.
This is also useful for scaling bitmaps in general as the only other way to scale bitmaps is to blit a wx.MemoryDC into another wx.MemoryDC.
The parameter quality determines what method to use for resampling the image, see ImageResizeQuality documentation.
It should be noted that although using IMAGE_QUALITY_HIGH
produces much nicer looking results it is a slower method. Downsampling will use the box averaging method which seems to operate very fast. If you are upsampling larger images using this method you will most likely notice that it is a bit slower and in extreme cases it will be quite substantially slower as the bicubic algorithm has to process a lot of data.
It should also be noted that the high quality scaling may not work as expected when using a single mask colour for transparency, as the scaling will blur the image and will therefore remove the mask partially. Using the alpha channel will work.
Example:
# get the bitmap from somewhere
bmp = wx.Bitmap('my_png.png', wx.BITMAP_TYPE_PNG)
# rescale it to have size of 32*32
if bmp.GetWidth() != 32 or bmp.GetHeight() != 32:
image = bmp.ConvertToImage()
bmp = wx.Bitmap(image.Scale(32, 32))
# another possibility:
image.Rescale(32, 32)
bmp = wx.Bitmap(image)
width (int) –
height (int) –
quality (ImageResizeQuality) –
Note
The algorithm used for the default (normal) quality value doesn’t work with images larger than 65536 (2^16) pixels in either dimension for 32-bit programs. For 64-bit programs the limit is 2^48 and so not relevant in practice.
See also
SetAlpha
(self, *args, **kw)¶SetAlpha (self, x, y, alpha)
Sets the alpha value for the given pixel.
This function should only be called if the image has alpha channel data, use HasAlpha
to check for this.
x (int) –
y (int) –
alpha (int) –
SetAlpha (self, alpha)
This function is similar to SetData
and has similar restrictions.
The pointer passed to it may however be None
in which case the function will allocate the alpha array internally – this is useful to add alpha channel data to an image which doesn’t have any.
If the pointer is not None
, it must have one byte for each image pixel and be allocated with malloc(). wx.Image takes ownership of the pointer and will free it unless static_data parameter is set to True
– in this case the caller should do it.
SetAlphaBuffer
(self, alpha)¶Sets the internal image alpha pointer to point at a Python buffer
object. This can save making an extra copy of the data but you must
ensure that the buffer object lives lives at least as long as the
Image
does.
SetData
(self, *args, **kw)¶SetData (self, data)
Sets the image data without performing checks.
The data given must have the size (widthheight3) or results will be unexpected. Don’t use this method if you aren’t sure you know what you are doing.
The data must have been allocated with malloc()
, NOT with operator
new.
If static_data is False
, after this call the pointer to the data is owned by the wx.Image object, that will be responsible for deleting it. Do not pass to this function a pointer obtained through GetData
.
SetData (self, data, new_width, new_height)
SetDataBuffer
(self, *args, **kw)¶Sets the internal image data pointer to point at a Python buffer object. This can save making an extra copy of the data but you must ensure that the buffer object lives lives at least as long as the
Image
does.
SetDataBuffer (self, data)
SetDataBuffer (self, data, new_width, new_height)
SetDefaultLoadFlags
(flags)¶Sets the default value for the flags used for loading image files.
This method changes the global value of the flags used for all the subsequently created wx.Image objects by default. It doesn’t affect the already existing objects.
By default, the global flags include Load_Verbose
flag value.
flags (int) –
New in version 4.1/wxWidgets-3.1.0.
See also
SetLoadFlags
(self, flags)¶Sets the flags used for loading image files by this object.
The flags will affect any future calls to LoadFile
for this object. To change the flags for all image objects, call SetDefaultLoadFlags
before creating any of them.
Currently the only defined flag is Load_Verbose
which determines if the non-fatal (i.e. not preventing the file from being loaded completely) problems should result in the calls to wx.LogWarning
function. It is recommended to customize handling of these warnings by e.g. defining a custom log target (see Logging Overview), but if such warnings should be completely suppressed, clearing this flag provides a simple way to do it, for example:
image = wx.Image()
image.SetLoadFlags(image.GetLoadFlags() & ~wx.Image.Load_Verbose)
image.LoadFile(...)
flags (int) –
New in version 4.1/wxWidgets-3.1.0.
See also
SetMask
(self, hasMask=True)¶Specifies whether there is a mask or not.
The area of the mask is determined by the current mask colour.
hasMask (bool) –
SetMaskColour
(self, red, green, blue)¶Sets the mask colour for this image (and tells the image to use the mask).
red (int) –
green (int) –
blue (int) –
SetMaskFromImage
(self, mask, mr, mg, mb)¶Sets image’s mask so that the pixels that have RGB
value of mr,mg,mb in mask will be masked in the image.
This is done by first finding an unused colour in the image, setting this colour as the mask colour and then using this colour to draw all pixels in the image who corresponding pixel in mask has given RGB
value.
The parameter mask is the mask image to extract mask shape from. It must have the same dimensions as the image.
The parameters mr, mg, mb are the RGB
values of the pixels in mask that will be used to create the mask.
mask (wx.Image) –
mr (int) –
mg (int) –
mb (int) –
bool
Returns False
if mask does not have same dimensions as the image or if there is no unused colour left. Returns True
if the mask was successfully applied.
Note
Note that this method involves computing the histogram, which is a computationally intensive operation.
SetOption
(self, *args, **kw)¶SetOption (self, name, value)
Sets a user-defined option.
The function is case-insensitive to name.
For example, when saving as a JPEG
file, the option quality is used, which is a number between 0 and 100 (0 is terrible, 100 is very good).
The lists of the currently supported options are in GetOption
and GetOptionInt
function docs.
name (string) –
value (string) –
See also
GetOption
, GetOptionInt
, HasOption
SetOption (self, name, value)
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
name (string) –
value (int) –
SetPalette
(self, palette)¶Associates a palette with the image.
The palette may be used when converting wx.Image to wx.Bitmap (MSW only at present) or in file save operations (none as yet).
palette (wx.Palette) –
SetRGB
(self, *args, **kw)¶SetRGB (self, x, y, r, g, b)
Set the color of the pixel at the given x and y coordinate.
x (int) –
y (int) –
r (int) –
g (int) –
b (int) –
SetRGB (self, rect, red, green, blue)
Sets the colour of the pixels within the given rectangle.
This routine performs bounds-checks for the coordinate so it can be considered a safe way to manipulate the data.
rect (wx.Rect) –
red (int) –
green (int) –
blue (int) –
SetType
(self, type)¶Set the type of image returned by GetType
.
This method is mostly used internally by the library but can also be called from the user code if the image was created from data in the given bitmap format without using LoadFile
(which would set the type correctly automatically).
Notice that the image must be created before this function is called.
type (BitmapType) – One of bitmap type constants, BITMAP_TYPE_INVALID
is a valid value for it and can be used to reset the bitmap type to default but BITMAP_TYPE_MAX
is not allowed here.
New in version 2.9.0.
Size
(self, size, pos, red=-1, green=-1, blue=-1)¶Returns a resized version of this image without scaling it by adding either a border with the given colour or cropping as necessary.
The image is pasted into a new image with the given size and background colour at the position pos relative to the upper left of the new image.
If red = green = blue = -1 then the areas of the larger image not covered by this image are made transparent by filling them with the image mask colour (which will be allocated automatically if it isn’t currently set).
Otherwise, the areas will be filled with the colour with the specified RGB
components.
See also
__bool__
(self)¶int
__nonzero__
(self)¶int
MaskBlue
¶See GetMaskBlue
MaskGreen
¶See GetMaskGreen
MaskRed
¶See GetMaskRed