This class encapsulates a platform-independent image.
An image can be created from data, or using 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 Image cannot (currently) be drawn directly to a DC. Instead, a platform-specific Bitmap object must be created from it using the Bitmap.wxBitmap(wxImage,int depth) constructor. This bitmap can then be drawn in a device context, using DC.DrawBitmap .
More on the difference between Image and Bitmap: 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, 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 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 Mask object associated to the bitmap object.
Starting from wxWidgets 2.5.0 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 Image.GetAlpha you should check if this image contains an alpha channel with 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 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 Image.AddHandler or call InitAllImageHandlers.
When saving in PCX format, 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, 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 Image.ConvertAlphaToMask ). Saving an animated GIF requires images of the same size (see GIFHandler.SaveAnimation)
See also
Bitmap, InitAllImageHandlers, PixelData
__init__ | Creates an empty Image object without an alpha channel. |
AddHandler | Register an image handler. |
AdjustChannels | This function muliplies all 4 channels (red, green, blue, alpha) with |
Blur | Blurs the image in both horizontal and vertical directions by the specified pixel blurRadius. |
BlurHorizontal | Blurs the image in the horizontal direction only. |
BlurVertical | Blurs the image in the vertical direction only. |
CanRead | Returns True if at least one of the available image handlers can read the file with the given name. |
CleanUpHandlers | Deletes all image handlers. |
Clear | Initialize the image data with zeroes (the default) or with the byte value given as value. |
ClearAlpha | Removes the alpha channel from the image. |
ComputeHistogram | Computes the histogram of the image. |
ConvertAlphaToMask | If the image has alpha channel, this method converts it to mask. |
ConvertToBitmap | ConvertToBitmap(depth=-1) -> Bitmap |
ConvertToDisabled | Returns disabled (dimmed) version of the image. |
ConvertToGreyscale | Returns a greyscale version of the image. |
ConvertToMono | Returns monochromatic version of the image. |
ConvertToMonoBitmap | ConvertToMonoBitmap(red, green, blue) -> Bitmap |
Copy | Returns an identical copy of this image. |
Create | Creates a fresh image. |
Destroy | Destroys the image data. |
FindFirstUnusedColour | Finds the first colour that is never used in the image. |
FindHandler | Finds the handler with the given name. |
FindHandlerMime | Finds the handler associated with the given MIME type. |
GetAlpha | Return alpha value at given pixel location. |
GetAlphaBuffer | Returns a writable Python buffer object that is pointing at the Alpha |
GetBlue | Returns the blue intensity at the given coordinate. |
GetDataBuffer | Returns a writable Python buffer object that is pointing at the RGB |
GetGreen | Returns the green intensity at the given coordinate. |
GetHeight | Gets the height of the image in pixels. |
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. |
GetImageExtWildcard | Iterates all registered ImageHandler objects, and returns a string containing file extension masks suitable for passing to file open/save dialog boxes. |
GetMaskBlue | Gets the blue value of the mask colour. |
GetMaskGreen | Gets the green value of the mask colour. |
GetMaskRed | Gets the red value of the mask colour. |
GetOption | Gets a user-defined string-valued option. |
GetOptionInt | Gets a user-defined integer-valued option. |
GetOrFindMaskColour | Get the current mask colour or find a suitable unused colour that could be used as a mask colour. |
GetPalette | Returns the palette associated with the image. |
GetRed | Returns the red intensity at the given coordinate. |
GetSize | Returns the size of the image in pixels. |
GetSubImage | Returns a sub image of the current one as long as the rect belongs entirely to the image. |
GetType | Gets the type of image found by LoadFile or specified with SaveFile . |
GetWidth | Gets the width of the image in pixels. |
HSVtoRGB | Converts a color in HSV color space to RGB color space. |
HasAlpha | Returns True if this image has alpha channel, False otherwise. |
HasMask | Returns True if there is a mask active, False otherwise. |
HasOption | Returns True if the given option is present. |
InitAlpha | Initializes the image alpha channel data. |
InitStandardHandlers | Internal use only. |
InsertHandler | Adds a handler at the start of the static list of format handlers. |
IsOk | Returns True if image data is present. |
IsTransparent | Returns True if the given pixel is transparent, i.e. |
LoadFile | Loads an image from an input stream. |
Mirror | Returns a mirrored copy of the image. |
Paste | Copy the data of the given image to the specified position in this image. |
RGBtoHSV | Converts a color in RGB color space to HSV color space. |
RemoveHandler | Finds the handler with the given name, and removes it. |
Replace | Replaces the colour specified by r1,g1,b1 by the colour r2,g2,b2. |
Rescale | 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. |
Resize | Changes the size of the image in-place without scaling it by adding either a border with the given colour or cropping as necessary. |
Rotate | Rotates the image about the given point, by angle radians. |
Rotate180 | Returns a copy of the image rotated by 180 degrees. |
Rotate90 | Returns a copy of the image rotated 90 degrees in the direction indicated by clockwise. |
RotateHue | Rotates the hue of each pixel in the image by angle, which is a float in the range of -1.0 to +1.0, where -1.0 corresponds to -360 degrees and +1.0 corresponds to +360 degrees. |
SaveFile | Saves an image in the given stream. |
Scale | Returns a scaled version of the image. |
SetAlpha | Sets the alpha value for the given pixel. |
SetAlphaBuffer | Sets the internal image alpha pointer to point at a Python buffer |
SetData | Sets the image data without performing checks. |
SetDataBuffer | Sets the internal image data pointer to point at a Python buffer |
SetMask | Specifies whether there is a mask or not. |
SetMaskColour | Sets the mask colour for this image (and tells the image to use the mask). |
SetMaskFromImage | Sets image’s mask so that the pixels that have RGB value of mr,mg,mb in mask will be masked in the image. |
SetOption | Sets a user-defined option. |
SetPalette | Associates a palette with the image. |
SetRGB | Sets the colour of the pixels within the given rectangle. |
SetType | Set the type of image returned by GetType . |
Size | Returns a resized version of this image without scaling it by adding either a border with the given colour or cropping as necessary. |
__nonzero__ |
Height | See GetHeight |
MaskBlue | See GetMaskBlue |
MaskGreen | See GetMaskGreen |
MaskRed | See GetMaskRed |
Type | See GetType and SetType |
Width | See GetWidth |
This class encapsulates a platform-independent image.
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)
Overloaded Implementations:
__init__ (self)
Creates an empty 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.
Parameters: |
|
---|
__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.
Parameters: |
|
---|
__init__ (self, name, type=BITMAP_TYPE_ANY, index=-1)
Creates an image from a file.
Parameters: |
|
---|
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 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.
Parameters: |
|
---|
__init__ (self, stream, type=BITMAP_TYPE_ANY, index=-1)
Creates an image from a stream.
Parameters: |
|
---|
__init__ (self, stream, mimetype, index=-1)
Creates an image from a stream using MIME-types to specify the type.
Parameters: |
|
---|
__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
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 InitAllImageHandlers to add handlers for all the image formats supported by wxWidgets at once.
Parameters: | handler (ImageHandler) – A heap-allocated handler object which will be deleted by Image if it is removed later by RemoveHandler or at program shutdown. |
---|
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.
Return type: | Image |
---|
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.
Parameters: | blurRadius (int) – |
---|---|
Return type: | Image |
See also
Blurs the image in the horizontal direction only.
This should not be used when using a single mask colour for transparency.
Parameters: | blurRadius (int) – |
---|---|
Return type: | Image |
See also
Blurs the image in the vertical direction only.
This should not be used when using a single mask colour for transparency.
Parameters: | blurRadius (int) – |
---|---|
Return type: | Image |
See also
Overloaded Implementations:
CanRead (filename)
Returns True if at least one of the available image handlers can read the file with the given name.
See ImageHandler.CanRead for more info.
Parameters: | filename (string) – |
---|---|
Return type: | bool |
CanRead (stream)
Returns True if at least one of the available image handlers can read the data in the given stream.
See ImageHandler.CanRead for more info.
Parameters: | stream (InputStream) – |
---|---|
Return type: | bool |
Deletes all image handlers.
This function is called by wxWidgets on exit.
Initialize the image data with zeroes (the default) or with the byte value given as value.
Parameters: | value (int) – |
---|
New in version 2.9.0.
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.
Computes the histogram of the image.
histogram is a reference to ImageHistogram object. 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
Parameters: | histogram (ImageHistogram) – |
---|---|
Return type: | int |
Returns: | Returns number of colours in the histogram. |
Overloaded Implementations:
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 by this function, see the overload below if you this is not appropriate.
Parameters: | threshold (int) – |
---|---|
Return type: | bool |
Returns: | 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.
Parameters: |
|
---|---|
Return type: | bool |
Returns: | Returns True on success, False on error. |
New in version 2.9.0.
ConvertToBitmap(depth=-1) -> Bitmap
Convert the image to a wx.Bitmap.
Returns disabled (dimmed) version of the image.
Parameters: | brightness (int) – |
---|---|
Return type: | Image |
New in version 2.9.0.
Overloaded Implementations:
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).
Parameters: |
|
---|---|
Return type: |
ConvertToGreyscale (self)
Returns a greyscale version of the image.
Return type: | Image |
---|
New in version 2.9.0.
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.
Parameters: |
|
---|---|
Return type: |
ConvertToMonoBitmap(red, green, blue) -> Bitmap
Creates a monochrome version of the image and returns it as a wx.Bitmap.
Overloaded Implementations:
Create (self, width, height, clear=True)
Creates a fresh image.
See Image.__init__ for more info.
Parameters: |
|
---|---|
Return type: | bool |
Returns: | 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.
Parameters: |
|
---|---|
Return type: | bool |
Create (self, width, height, data)
Return type: | bool |
---|
Create (self, width, height, data, alpha)
Return type: | bool |
---|
Create (self, size, data)
Return type: | bool |
---|
Create (self, size, data, alpha)
Return type: | bool |
---|
Destroys the image data.
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.
Parameters: |
|
---|---|
Return type: | tuple |
Returns: | ( r, g, b ) |
Note
This method involves computing the histogram, which is a computationally intensive operation.
Overloaded Implementations:
FindHandler (name)
Finds the handler with the given name.
Parameters: | name (string) – The handler name. |
---|---|
Return type: | ImageHandler |
Returns: | A pointer to the handler if found, None otherwise. |
See also
FindHandler (extension, imageType)
Finds the handler associated with the given extension and type.
Parameters: |
|
---|---|
Return type: | |
Returns: | A pointer to the handler if found, None otherwise. |
See also
FindHandler (imageType)
Finds the handler associated with the given image type.
Parameters: | imageType (BitmapType) – The image type; one of the BitmapType values. |
---|---|
Return type: | ImageHandler |
Returns: | A pointer to the handler if found, None otherwise. |
See also
Finds the handler associated with the given MIME type.
Parameters: | mimetype (string) – MIME type. |
---|---|
Return type: | ImageHandler |
Returns: | A pointer to the handler if found, None otherwise. |
See also
Overloaded Implementations:
GetAlpha (self, x, y)
Return alpha value at given pixel location.
Parameters: |
|
---|---|
Return type: | int |
GetAlpha (self)
Returns a copy of the Alpha bytes of the image.
Return type: | PyObject |
---|
Returns a writable Python buffer object that is pointing at the Alpha data buffer inside the wx.Image. You need to ensure that you do not use this buffer object after the image has been destroyed.
Return type: | PyObject |
---|
Returns the blue intensity at the given coordinate.
Parameters: |
|
---|---|
Return type: | int |
Returns a writable Python buffer object that is pointing at the RGB image data buffer inside the wx.Image. You need to ensure that you do not use this buffer object after the image has been destroyed.
Return type: | PyObject |
---|
Returns the green intensity at the given coordinate.
Parameters: |
|
---|---|
Return type: | int |
Gets the height of the image in pixels.
Return type: | int |
---|
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 ImageHandler.GetImageCount for more info.
The parameter type may be one of the following values:
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). |
---|
Overloaded Implementations:
GetImageCount (filename, type=BITMAP_TYPE_ANY)
Parameters: |
|
---|---|
Return type: | int |
GetImageCount (stream, type=BITMAP_TYPE_ANY)
Parameters: |
|
---|---|
Return type: | int |
Iterates all registered ImageHandler objects, and returns a string containing file extension masks suitable for passing to file open/save dialog boxes.
Return type: | string |
---|---|
Returns: | 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
Gets the blue value of the mask colour.
Return type: | int |
---|
Gets the green value of the mask colour.
Return type: | int |
---|
Gets the red value of the mask colour.
Return type: | int |
---|
Gets a user-defined string-valued option.
Generic options:
Options specific to GIFHandler:
Parameters: | name (string) – The name of the option, case-insensitive. |
---|---|
Return type: | string |
Returns: | 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
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:
New in version 2.9.3.
Options specific to PNGHandler:
Options specific to TIFFHandler:
Parameters: | name (string) – The name of the option, case-insensitive. |
---|---|
Return type: | int |
Returns: | 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.
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.
Return type: | tuple |
---|---|
Returns: | ( r, g, b ) |
Returns the palette associated with the image.
Currently the palette is only used when converting to Bitmap under Windows.
Some of the 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).
Return type: | Palette |
---|
Returns the red intensity at the given coordinate.
Parameters: |
|
---|---|
Return type: | int |
Returns a sub image of the current one as long as the rect belongs entirely to the image.
Parameters: | rect (Rect) – |
---|---|
Return type: | Image |
Gets the type of image found by LoadFile or specified with SaveFile .
Return type: | BitmapType |
---|
New in version 2.9.0.
Gets the width of the image in pixels.
Return type: | int |
---|
Converts a color in HSV color space to RGB color space.
Parameters: | hsv (HSVValue) – |
---|---|
Return type: | RGBValue |
Returns True if this image has alpha channel, False otherwise.
Return type: | bool |
---|
Returns True if there is a mask active, False otherwise.
Return type: | bool |
---|
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.
Parameters: | name (string) – |
---|---|
Return type: | bool |
See also
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.
Internal use only.
Adds standard image format handlers. It only install BMPHandler for the time being, which is used by Bitmap.
This function is called by wxWidgets on startup, and shouldn’t be called by the user.
See also
ImageHandler, InitAllImageHandlers, Quantize
Adds a handler at the start of the static list of format handlers.
Parameters: | handler (ImageHandler) – A new image format handler object. There is usually only one instance of a given handler class in an application session. |
---|
See also
Returns True if image data is present.
Return type: | bool |
---|
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.
Parameters: |
|
---|---|
Return type: | bool |
Overloaded Implementations:
LoadFile (self, stream, type=BITMAP_TYPE_ANY, index=-1)
Loads an image from an input stream.
Parameters: |
|
---|---|
Return type: | bool |
Returns: | True if the operation succeeded, False otherwise. If the optional index parameter is out of range, False is returned and a call to 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.
Parameters: |
|
---|---|
Return type: | 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.
Parameters: |
|
---|---|
Return type: | bool |
LoadFile (self, stream, mimetype, index=-1)
Loads an image from an input stream.
Parameters: |
|
---|---|
Return type: | bool |
Returns a mirrored copy of the image.
The parameter horizontally indicates the orientation.
Parameters: | horizontally (bool) – |
---|---|
Return type: | Image |
Copy the data of the given image to the specified position in this image.
Parameters: |
|
---|
Converts a color in RGB color space to HSV color space.
Parameters: | rgb (RGBValue) – |
---|---|
Return type: | HSVValue |
Finds the handler with the given name, and removes it.
The handler is also deleted.
Parameters: | name (string) – The handler name. |
---|---|
Return type: | bool |
Returns: | True if the handler was found and removed, False otherwise. |
See also
Replaces the colour specified by r1,g1,b1 by the colour r2,g2,b2.
Parameters: |
|
---|
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.
Parameters: |
|
---|---|
Return type: |
See also
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.
Parameters: | |
---|---|
Return type: | |
Returns: | The (modified) image itself. |
See also
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.
Parameters: | |
---|---|
Return type: |
Returns a copy of the image rotated by 180 degrees.
Return type: | Image |
---|
New in version 2.9.2.
Returns a copy of the image rotated 90 degrees in the direction indicated by clockwise.
Parameters: | clockwise (bool) – |
---|---|
Return type: | Image |
Rotates the hue of each pixel in the image by angle, which is a float in the range of -1.0 to +1.0, where -1.0 corresponds to -360 degrees and +1.0 corresponds to +360 degrees.
Parameters: | angle (float) – |
---|
Overloaded Implementations:
SaveFile (self, stream, mimetype)
Saves an image in the given stream.
Parameters: |
|
---|---|
Return type: | bool |
Returns: | 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.
Parameters: |
|
---|---|
Return type: | bool |
SaveFile (self, name, mimetype)
Saves an image in the named file.
Parameters: |
|
---|---|
Return 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.
Parameters: | name (string) – Name of the file to save the image to. |
---|---|
Return type: | bool |
SaveFile (self, stream, type)
Saves an image in the given stream.
Parameters: |
|
---|---|
Return type: | bool |
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 MemoryDC into another 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.BitmapFromImage(image.Scale(32, 32))
# another possibility:
image.Rescale(32, 32)
bmp = wx.BitmapFromImage(image)
Parameters: |
|
---|---|
Return type: |
See also
Overloaded Implementations:
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.
Parameters: |
|
---|
SetAlpha (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 wx.Image does.
Overloaded Implementations:
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 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)
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 wx.Image does.
Overloaded Implementations:
SetDataBuffer (self, data)
SetDataBuffer (self, data, new_width, new_height)
Specifies whether there is a mask or not.
The area of the mask is determined by the current mask colour.
Parameters: | hasMask (bool) – |
---|
Sets the mask colour for this image (and tells the image to use the mask).
Parameters: |
|
---|
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.
Parameters: |
|
---|---|
Return type: | bool |
Returns: | 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.
Overloaded Implementations:
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.
Parameters: |
|
---|
See also
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.
Parameters: |
|
---|
Associates a palette with the image.
The palette may be used when converting Image to Bitmap (MSW only at present) or in file save operations (none as yet).
Parameters: | palette (Palette) – |
---|
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.
Parameters: |
|
---|
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.
Parameters: | 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.
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.
Parameters: | |
---|---|
Return type: |
See also
Return type: | int |
---|
See GetMaskBlue
See GetMaskGreen
See GetMaskRed