******** wx.Image ******** Inheritance diagram for `wx.Image`: | .. inheritance-diagram:: wx.Image | Description =========== 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 `ConvertToBitmap <#ConvertToBitmap>`_ method. This bitmap can then be drawn in a device context, using `wx.DC.DrawBitmap `_. 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. `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. Unlike RGB data, not all images have an alpha channel and before using `GetAlpha <#GetAlpha>`_ you should check if this image contains an alpha channel with `HasAlpha <#HasAlpha>`_. .. note:: Note that currently only images loaded from PNG files with transparency information will have an alpha channel. .. seealso:: `wx.Bitmap `_ Derived From ^^^^^^^^^^^^^ * `wx.Object `_ Methods Summary ^^^^^^^^^^^^^^^ * `__init__ <#__init__>`_ * `AddHandler <#AddHandler>`_ * `AdjustChannels <#AdjustChannels>`_ * `Blur <#Blur>`_ * `BlurHorizontal <#BlurHorizontal>`_ * `BlurVertical <#BlurVertical>`_ * `CanRead <#CanRead>`_ * `CanReadStream <#CanReadStream>`_ * `ComputeHistogram <#ComputeHistogram>`_ * `ConvertAlphaToMask <#ConvertAlphaToMask>`_ * `ConvertColourToAlpha <#ConvertColourToAlpha>`_ * `ConvertToBitmap <#ConvertToBitmap>`_ * `ConvertToGreyscale <#ConvertToGreyscale>`_ * `ConvertToMono <#ConvertToMono>`_ * `ConvertToMonoBitmap <#ConvertToMonoBitmap>`_ * `Copy <#Copy>`_ * `CountColours <#CountColours>`_ * `Create <#Create>`_ * `FindFirstUnusedColour <#FindFirstUnusedColour>`_ * `GetAlpha <#GetAlpha>`_ * `GetAlphaBuffer <#GetAlphaBuffer>`_ * `GetAlphaData <#GetAlphaData>`_ * `GetBlue <#GetBlue>`_ * `GetData <#GetData>`_ * `GetDataBuffer <#GetDataBuffer>`_ * `GetGreen <#GetGreen>`_ * `GetHandlers <#GetHandlers>`_ * `GetHeight <#GetHeight>`_ * `GetImageCount <#GetImageCount>`_ * `GetImageExtWildcard <#GetImageExtWildcard>`_ * `GetMaskBlue <#GetMaskBlue>`_ * `GetMaskGreen <#GetMaskGreen>`_ * `GetMaskRed <#GetMaskRed>`_ * `GetOption <#GetOption>`_ * `GetOptionInt <#GetOptionInt>`_ * `GetOrFindMaskColour <#GetOrFindMaskColour>`_ * `GetRed <#GetRed>`_ * `GetSize <#GetSize>`_ * `GetSubImage <#GetSubImage>`_ * `GetWidth <#GetWidth>`_ * `HSVtoRGB <#HSVtoRGB>`_ * `HasAlpha <#HasAlpha>`_ * `HasMask <#HasMask>`_ * `HasOption <#HasOption>`_ * `InitAlpha <#InitAlpha>`_ * `InsertHandler <#InsertHandler>`_ * `IsOk <#IsOk>`_ * `IsTransparent <#IsTransparent>`_ * `LoadFile <#LoadFile>`_ * `LoadMimeFile <#LoadMimeFile>`_ * `LoadMimeStream <#LoadMimeStream>`_ * `LoadStream <#LoadStream>`_ * `Mirror <#Mirror>`_ * `Paste <#Paste>`_ * `RGBtoHSV <#RGBtoHSV>`_ * `RemoveHandler <#RemoveHandler>`_ * `Replace <#Replace>`_ * `ResampleBicubic <#ResampleBicubic>`_ * `ResampleBox <#ResampleBox>`_ * `Rescale <#Rescale>`_ * `Resize <#Resize>`_ * `Rotate <#Rotate>`_ * `Rotate90 <#Rotate90>`_ * `RotateHue <#RotateHue>`_ * `SaveFile <#SaveFile>`_ * `SaveMimeFile <#SaveMimeFile>`_ * `SaveMimeStream <#SaveMimeStream>`_ * `SaveStream <#SaveStream>`_ * `Scale <#Scale>`_ * `SetAlpha <#SetAlpha>`_ * `SetAlphaBuffer <#SetAlphaBuffer>`_ * `SetAlphaData <#SetAlphaData>`_ * `SetData <#SetData>`_ * `SetDataBuffer <#SetDataBuffer>`_ * `SetMask <#SetMask>`_ * `SetMaskColour <#SetMaskColour>`_ * `SetMaskFromImage <#SetMaskFromImage>`_ * `SetOption <#SetOption>`_ * `SetOptionInt <#SetOptionInt>`_ * `SetRGB <#SetRGB>`_ * `SetRGBRect <#SetRGBRect>`_ * `ShrinkBy <#ShrinkBy>`_ * `Size <#Size>`_ Properties Summary ^^^^^^^^^^^^^^^^^^ * `AlphaBuffer <#AlphaBuffer>`_ * `AlphaData <#AlphaData>`_ * `Data <#Data>`_ * `DataBuffer <#DataBuffer>`_ * `Height <#Height>`_ * `MaskBlue <#MaskBlue>`_ * `MaskGreen <#MaskGreen>`_ * `MaskRed <#MaskRed>`_ * `Width <#Width>`_ Class API ========= Methods ^^^^^^^ .. method:: __init__(name, type=wx.BITMAP_TYPE_ANY, index=-1) Loads an image from a file. **Parameters:** * `name` (string): Name of the file from which to load the image. * `type` (int): One of the following values: ============================ ===================================== Bitmap Type Constant Description ============================ ===================================== ``wx.BITMAP_TYPE_BMP`` Load a Windows image file. ``wx.BITMAP_TYPE_GIF`` Load a GIF image file. ``wx.BITMAP_TYPE_JPEG`` Load a JPEG image file. ``wx.BITMAP_TYPE_PCX`` Load a PCX image file. ``wx.BITMAP_TYPE_PNG`` Load a PNG image file. ``wx.BITMAP_TYPE_PNM`` Load a PNM image file. ``wx.BITMAP_TYPE_TIF`` Load a TIFF image file. ``wx.BITMAP_TYPE_XPM`` Load a XPM image 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 to choose the default image and is interpreted as the first image (the one with `index` = 0) by the GIF and TIFF handler and as the largest and most colourful one by the ICO handler. | **Returns:** `wx.Image `_ -------- .. method:: AddHandler(handler) Adds a handler to the end of the static list of format handlers. **Parameters:** * `handler` (`wx.ImageHandler `_): A new image format handler object. There is usually only one instance of a given handler class in an application session. -------- .. method:: AdjustChannels(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. **Parameters:** * `factor_red` (double) * `factor_green` (double) * `factor_blue` (double) * `factor_alpha` (double) | **Returns:** `wx.Image `_ -------- .. method:: Blur(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. **Parameters:** * `blurRadius` (int) | **Returns:** `wx.Image `_ .. seealso:: `BlurHorizontal <#BlurHorizontal>`_, `BlurVertical <#BlurVertical>`_ -------- .. method:: BlurHorizontal(blurRadius) Blurs the image in the horizontal direction only. This should not be used when using a single mask colour for transparency. **Parameters:** * `blurRadius` (int) | **Returns:** `wx.Image `_ .. seealso:: `Blur <#Blur>`_, `BlurVertical <#BlurVertical>`_ -------- .. method:: BlurVertical(blurRadius) Blurs the image in the vertical direction only. This should not be used when using a single mask colour for transparency. **Parameters:** * `blurRadius` (int) | **Returns:** `wx.Image `_ .. seealso:: `Blur <#Blur>`_, `BlurHorizontal <#BlurHorizontal>`_ -------- .. method:: CanRead(filename) Returns ``True`` if the image handlers can read this file. **Parameters:** * `filename` (string) | **Returns:** `bool` -------- .. method:: CanReadStream(stream) Returns ``True`` if the image handlers can read an image file from the data currently on the input stream, or a readable Python file-like object. **Parameters:** * `stream` (`wx.InputStream `_) | **Returns:** `bool` -------- .. method:: ComputeHistogram(histogram) Computes the histogram of the image. `histogram` is a reference to `wx.ImageHistogram` object. `wx.ImageHistogram` is a specialization of `wx.HashMap` "template". **Parameters:** * `histogram` (`wx.ImageHistogram`) | **Returns:** `unsigned long` -------- .. method:: ConvertAlphaToMask(threshold=128) If the image has alpha channel, this method converts it to mask. All pixels with alpha value less than `threshold` are replaced with mask colour and the alpha channel is removed. Mask colour is chosen automatically using `FindFirstUnusedColour <#FindFirstUnusedColour>`_. If the image image doesn't have alpha channel, `ConvertAlphaToMask` does nothing. **Parameters:** * `threshold` (int) | **Returns:** `bool` -------- .. method:: ConvertColourToAlpha(r, g, b) This method converts an image where the original alpha information is only available as a shades of a colour (actually shades of grey) typically when you draw anti-aliased text into a bitmap. The DC drawing routines draw grey values on the black background although they actually mean to draw white with differnt alpha values. This method reverses it, assuming a black (!) background and white text. The method will then fill up the whole image with the colour given. **Parameters:** * `r` (byte) * `g` (byte) * `b` (byte) | **Returns:** `bool` -------- .. method:: ConvertToBitmap(depth) Convert the image to a `wx.Bitmap `_. **Parameters:** * `depth` (int) | **Returns:** `wx.Bitmap `_ -------- .. method:: ConvertToGreyscale(lr=0.299, lg=0.587, lb=0.114) Returns a greyscale version of the image. The returned image uses the luminance component of the original to calculate the greyscale. Defaults to using ITU-T BT.601 when converting to YUV, where every pixel equals (R \* `lr`) + (G \* `lg`) + (B \* `lb`). **Parameters:** * `lr` (double) * `lg` (double) * `lb` (double) | **Returns:** `wx.Image `_ -------- .. method:: ConvertToMono(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. **Parameters:** * `r` (byte) * `g` (byte) * `b` (byte) | **Returns:** `wx.Image `_ -------- .. method:: ConvertToMonoBitmap(r, g, b) Returns a monochromatic `wx.Bitmap `_ version of the image. The returned image has white colour where the original has (`r`, `g`, `b`) colour and black colour everywhere else. **Parameters:** * `r` (byte) * `g` (byte) * `b` (byte) | **Returns:** `wx.Bitmap `_ -------- .. method:: Copy() Returns an identical copy of the image. | **Returns:** `wx.Image `_ -------- .. method:: CountColours() `No docstrings available for this method.` -------- .. method:: Create(width, height, clear=True) Creates a fresh image. If `clear` is ``True``, the new image will be initialized to black. Otherwise, the image data will be uninitialized. **Parameters:** * `width` (int): The width of the image in pixels. * `height` (int): The height of the image in pixels. * `clear` (bool) | **Returns:** `bool` -------- .. method:: FindFirstUnusedColour(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. Returns a tuple consisting of a success flag and rgb values. **Parameters:** * `startR` (int) * `startG` (int) * `startB` (int) | **Returns:** `(success, r, g, b)` .. note:: Note that this method involves computing the histogram, which is computationally intensive operation. -------- .. method:: GetAlpha(x, y) Returns the alpha value for the given pixel. This function may only be called for the images with alpha channel, use `HasAlpha <#HasAlpha>`_ to check for this. The returned value is the opacity of the image, i.e. the value of 0 corresponds to the fully transparent pixels while the value of 255 to the fully opaque pixels. **Parameters:** * `x` (int) * `y` (int) | **Returns:** `byte` -------- .. method:: GetAlphaBuffer() 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. | **Returns:** `PyObject` -------- .. method:: GetAlphaData() Returns a string containing a copy of the alpha bytes of the image. | **Returns:** `PyObject` -------- .. method:: GetBlue(x, y) Returns the blue intensity at the given coordinate. **Parameters:** * `x` (int) * `y` (int) | **Returns:** `byte` -------- .. method:: GetData() Returns the image data as an array. This is most often used when doing direct image manipulation. The return value points to an array of characters in RGBRGBRGB... format in the top-to-bottom, left-to-right order, that is the first RGB triplet corresponds to the pixel first pixel of the first row, the second one --- to the second pixel of the first row and so on until the end of the first row, with second row following after it and so on. You should not delete the returned pointer nor pass it to `SetData <#SetData>`_. | **Returns:** `unsigned string` -------- .. method:: GetDataBuffer() 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. | **Returns:** `PyObject` -------- .. method:: GetGreen(x, y) Returns the green intensity at the given coordinate. **Parameters:** * `x` (int) * `y` (int) | **Returns:** `byte` -------- .. method:: GetHandlers() Returns the static list of image format handlers. | **Returns:** `list of objects` .. seealso:: `wx.ImageHandler `_ -------- .. method:: GetHeight() Gets the height of the image in pixels. | **Returns:** `int` -------- .. method:: 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. | **Returns:** `int` -------- .. method:: GetImageExtWildcard() Iterates all registered wx.ImageHandler objects, and returns a string containing file extension masks suitable for passing to file open/save dialog boxes. | **Returns:** `string` .. seealso:: `wx.ImageHandler `_ -------- .. method:: GetMaskBlue() Gets the blue value of the mask colour. | **Returns:** `int` -------- .. method:: GetMaskGreen() Gets the green value of the mask colour. | **Returns:** `int` -------- .. method:: GetMaskRed() Gets the red value of the mask colour. | **Returns:** `int` -------- .. method:: GetOption(name) Gets 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). **Parameters:** * `name` (string) | **Returns:** `string` .. seealso:: `SetOption <#SetOption>`_, `GetOptionInt <#GetOptionInt>`_, `HasOption <#HasOption>`_ -------- .. method:: GetOptionInt(name) Gets a user-defined option as an integer. The function is case-insensitive to `name`. If the given option is not present, the function returns 0. Use `HasOption <#HasOption>`_ is 0 is a possibly valid value for the option. Options for `wx.PNGHandler`: ==================================== ======================================== Option Constant Description ==================================== ======================================== ``wx.IMAGE_OPTION_PNG_FORMAT`` Format for saving a PNG file. ``wx.IMAGE_OPTION_PNG_BITDEPTH`` Bit depth for every channel (R/G/B/A). ==================================== ======================================== | Supported values for ``wx.IMAGE_OPTION_PNG_FORMAT``: ==================================== ======================================== ``wx.PNG_TYPE_COLOUR`` Stores RGB image. ``wx.PNG_TYPE_GREY`` Stores grey image, converts from RGB. ``wx.PNG_TYPE_GREY_RED`` Stores grey image, uses red value as grey. ==================================== ======================================== | **Parameters:** * `name` (string) | **Returns:** `int` .. seealso:: `SetOption <#SetOption>`_, `GetOption <#GetOption>`_ -------- .. method:: GetOrFindMaskColour() 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. | **Returns:** `bool` -------- .. method:: GetRed(x, y) Returns the red intensity at the given coordinate. **Parameters:** * `x` (int) * `y` (int) | **Returns:** `byte` -------- .. method:: GetSize() Returns the size of the image in pixels. | **Returns:** `wx.Size `_ -------- .. method:: GetSubImage(rect) Returns a sub image of the current one as long as the rect belongs entirely to the image. **Parameters:** * `rect` (`wx.Rect `_) | **Returns:** `wx.Image `_ -------- .. method:: GetWidth() Gets the width of the image in pixels. | **Returns:** `int` .. seealso:: `GetHeight <#GetHeight>`_ -------- .. method:: HSVtoRGB(hsv) Converts a color in HSV color space to RGB color space. **Parameters:** * `hsv` (`wx.Image_HSVValue `_) | **Returns:** `wx.Image_RGBValue `_ -------- .. method:: HasAlpha() Returns ``True`` if this image has alpha channel, ``False`` otherwise. | **Returns:** `bool` .. seealso:: `GetAlpha <#GetAlpha>`_, `SetAlpha <#SetAlpha>`_ -------- .. method:: HasMask() Returns ``True`` if there is a mask active, ``False`` otherwise. | **Returns:** `bool` -------- .. method:: HasOption(name) Returns ``True`` if the given option is present. The function is case-insensitive to `name`. **Parameters:** * `name` (string) | **Returns:** `bool` .. seealso:: `SetOption <#SetOption>`_, `GetOption <#GetOption>`_, `GetOptionInt <#GetOptionInt>`_ -------- .. method:: InitAlpha() 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 a mask colour, all mask pixels will be completely transparent. -------- .. method:: InsertHandler(handler) Adds a handler at the start of the static list of format handlers. **Parameters:** * `handler` (`wx.ImageHandler `_): A new image format handler object. There is usually only one instance of a given handler class in an application session. .. seealso:: `wx.ImageHandler `_ -------- .. method:: IsOk() Returns ``True`` if image data is present. | **Returns:** `bool` -------- .. method:: IsTransparent(x, y, threshold=128) 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:** * `x` (int) * `y` (int) * `threshold` (int) | **Returns:** `bool` -------- .. method:: LoadFile(name, type=wx.BITMAP_TYPE_ANY, index=-1) Loads an image from an input stream. **Parameters:** * `name` (string): Name of the file from which to load the image. * `type` (int): One of the following values: ============================ ===================================== Bitmap Type Constant Description ============================ ===================================== ``wx.BITMAP_TYPE_BMP`` Load a Windows image file. ``wx.BITMAP_TYPE_GIF`` Load a GIF image file. ``wx.BITMAP_TYPE_JPEG`` Load a JPEG image file. ``wx.BITMAP_TYPE_PCX`` Load a PCX image file. ``wx.BITMAP_TYPE_PNG`` Load a PNG image file. ``wx.BITMAP_TYPE_PNM`` Load a PNM image file. ``wx.BITMAP_TYPE_TIF`` Load a TIFF image file. ``wx.BITMAP_TYPE_XPM`` Load a XPM image 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 to choose the default image and is interpreted as the first image (the one with `index` = 0) by the GIF and TIFF handler and as the largest and most colourful one by the ICO handler | **Returns:** `bool` .. note:: Depending on how wxWidgets has been configured, not all formats may be available. .. note:: you can use `GetOptionInt <#GetOptionInt>`_ to set the hotspot before saving an image into a cursor file (default hotspot is in the centre of the image):: hotspot_x = image.GetOptionInt(wx.IMAGE_OPTION_CUR_HOTSPOT_X) hotspot_y = image.GetOptionInt(wx.IMAGE_OPTION_CUR_HOTSPOT_Y) .. seealso:: `SaveFile <#SaveFile>`_ -------- .. method:: LoadMimeFile(name, mimetype, index=-1) Loads an image from a file, specifying the image type with a MIME type string. **Parameters:** * `name` (string) * `mimetype` (string) * `index` (int) | **Returns:** `bool` -------- .. method:: LoadMimeStream(stream, mimetype, index=-1) Loads an image from an input stream or a readable Python file-like object, using a MIME type string to specify the image file format. **Parameters:** * `stream` (`wx.InputStream `_) * `mimetype` (string) * `index` (int) | **Returns:** `bool` -------- .. method:: LoadStream(stream, type=wx.BITMAP_TYPE_ANY, index=-1) Loads an image from an input stream or a readable Python file-like object. If no handler type is provided, the library will try to autodetect the format. **Parameters:** * `stream` (`wx.InputStream `_) * `type` (long) * `index` (int) | **Returns:** `bool` -------- .. method:: Mirror(horizontally=True) Returns a mirrored copy of the image. The parameter `horizontally` indicates the orientation. **Parameters:** * `horizontally` (bool) | **Returns:** `wx.Image `_ -------- .. method:: Paste(image, x, y) Pastes `image` into this instance and takes care of the mask colour and any out of bounds problems. **Parameters:** * `image` (`wx.Image `_) * `x` (int) * `y` (int) -------- .. method:: RGBtoHSV(rgb) Converts a color in RGB color space to HSV color space. **Parameters:** * `rgb` (`wx.Image_RGBValue `_) | **Returns:** `wx.Image_HSVValue `_ -------- .. method:: RemoveHandler(name) Finds the handler with the given name, and removes it. The handler is not deleted. **Parameters:** * `name` (string): The handler name. | **Returns:** `bool` .. seealso:: `wx.ImageHandler `_ -------- .. method:: Replace(r1, g1, b1, r2, g2, b2) Replaces the colour specified by `r1`, `g1`, `b1` by the colour `r2`, `g2`, `b2`. **Parameters:** * `r1` (int) * `g1` (int) * `b1` (int) * `r2` (int) * `g2` (int) * `b2` (int) -------- .. method:: ResampleBicubic(width, height) | **Parameters:** * `width` (int) * `height` (int) | **Returns:** `wx.Image `_ -------- .. method:: ResampleBox(width, height) | **Parameters:** * `width` (int) * `height` (int) | **Returns:** `wx.Image `_ -------- .. method:: Rescale(width, height, quality=wx.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 <#Scale>`_ function. Returns the (modified) image itself. **Parameters:** * `width` (int) * `height` (int) * `quality` (int) | **Returns:** `wx.Image `_ .. seealso:: `Scale <#Scale>`_ -------- .. method:: Resize(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. Returns the (modified) image itself. **Parameters:** * `size` (`wx.Size `_) * `pos` (`wx.Point `_) * `red` (int) * `green` (int) * `blue` (int) | **Returns:** `wx.Image `_ .. seealso:: `Size <#Size>`_ -------- .. method:: Rotate(angle, centre_of_rotation, interpolating=True, offset_after_rotation=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. **Parameters:** * `angle` (double) * `centre_of_rotation` (`wx.Point `_) * `interpolating` (bool) * `offset_after_rotation` (`wx.Point `_) | **Returns:** `wx.Image `_ -------- .. method:: Rotate90(clockwise=True) Returns a copy of the image rotated 90 degrees in the direction indicated by `clockwise`. **Parameters:** * `clockwise` (bool) | **Returns:** `wx.Image `_ -------- .. method:: RotateHue(angle) Rotates the hue of each pixel in the image by `angle`, which is a double 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` (double) -------- .. method:: SaveFile(name, type) Saves an image in the given stream. **Parameters:** * `name` (string): Name of the file to save the image to. * `type` (int): Currently these types can be used: ============================ ===================================== Bitmap Type Constant Description ============================ ===================================== ``wx.BITMAP_TYPE_BMP`` Save a Windows image file. ``wx.BITMAP_TYPE_JPEG`` Save a JPEG image file. ``wx.BITMAP_TYPE_PCX`` Save a PCX image file. ``wx.BITMAP_TYPE_PNG`` Save a PNG image file. ``wx.BITMAP_TYPE_PNM`` Save a PNM image file. ``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). ``wx.BITMAP_TYPE_CUR`` Save a Windows cursor file (CUR). ============================ ===================================== | **Returns:** `bool` .. note:: Depending on how wxWidgets has been configured, not all formats may be available. .. note:: you can use `GetOptionInt <#GetOptionInt>`_ to set the hotspot before saving an image into a cursor file (default hotspot is in the centre of the image):: hotspot_x = image.GetOptionInt(wx.IMAGE_OPTION_CUR_HOTSPOT_X) hotspot_y = image.GetOptionInt(wx.IMAGE_OPTION_CUR_HOTSPOT_Y) .. seealso:: `LoadFile <#LoadFile>`_ -------- .. method:: SaveMimeFile(name, mimetype) Saves an image in the named file. **Parameters:** * `name` (string) * `mimetype` (string) | **Returns:** `bool` -------- .. method:: SaveMimeStream(stream, mimetype) Saves an image in the named file. **Parameters:** * `stream` (`wx.OutputStream `_) * `mimetype` (string) | **Returns:** `bool` -------- .. method:: SaveStream(stream, type) Saves an image in the named file. **Parameters:** * `stream` (`wx.OutputStream `_) * `type` (int) | **Returns:** `bool` -------- .. method:: Scale(width, height, quality) 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`. It should be noted that although using ``wx.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("MyBitmap.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 = image **Parameters:** * `width` (int): The desired width * `height` (int): The desired height * `quality` (int): Determines what method to use for resampling the image. Can be one of the following: ================================ ====================================== Quality Flag Description ================================ ====================================== ``wx.IMAGE_QUALITY_NORMAL`` Uses the normal default scaling method of pixel replication ``wx.IMAGE_QUALITY_HIGH`` Uses bicubic and box averaging resampling methods for upsampling and downsampling respectively ================================ ====================================== | **Returns:** `wx.Image `_ .. seealso:: `Rescale <#Rescale>`_ -------- .. method:: SetAlpha(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 <#HasAlpha>`_ to check for this. **Parameters:** * `x` (int) * `y` (int) * `alpha` (byte) -------- .. method:: SetAlphaBuffer(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 as long as the `wx.Image` does. **Parameters:** * `alpha` (buffer) -------- .. method:: SetAlphaData(alpha) Resets the Image's alpha data from a buffer of bytes. Accepts either a string or a buffer object holding the data and the length of the data must be width\*height. **Parameters:** * `alpha` (buffer) -------- .. method:: SetData(data) Sets the image data without performing checks. The data given must have the size (width\*height\*3) or results will be unexpected. Don't use this method if you aren't sure you know what you are doing. 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 <#GetData>`_. **Parameters:** * `data` (unsigned string) -------- .. method:: SetDataBuffer(data) 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 longer than the `wx.Image` does. **Parameters:** * `data` (buffer) -------- .. method:: SetMask(hasMask=True) Specifies whether there is a mask or not. The area of the mask is determined by the current mask colour. **Parameters:** * `hasMask` (bool) -------- .. method:: SetMaskColour(red, green, blue) Sets the mask colour for this image (and tells the image to use the mask). **Parameters:** * `red` (byte) * `green` (byte) * `blue` (byte) -------- .. method:: SetMaskFromImage(mask) Sets the image's mask so that the pixels that have RGB value of (`mr`, `mg`, `mb`) in mask will be masked in this 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. 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. **Parameters:** * `mask` (`wx.Image `_): The mask image to extract mask shape from. Must have same dimensions as the image. | **Returns:** `bool` .. note:: Note that this method involves computing the histogram, which is computationally intensive operation. -------- .. method:: SetOption(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). **Parameters:** * `name` (string) * `value` (string) .. seealso:: `GetOption <#GetOption>`_, `GetOptionInt <#GetOptionInt>`_, `HasOption <#HasOption>`_ -------- .. method:: SetOptionInt(name, value) Sets an image option as an integer. **Parameters:** * `name` (string) * `value` (int) -------- .. method:: SetRGB(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. **Parameters:** * `rect` (`wx.Rect `_) * `red` (int) * `green` (int) * `blue` (int) -------- .. method:: SetRGBRect(rect, r, g, b) Sets the colour of the pixels within the given rectangle. This routine performs bounds-checks for the rectangle so it can be considered a safe way to manipulate the data. **Parameters:** * `rect` (`wx.Rect `_) * `r` (byte) * `g` (byte) * `b` (byte) -------- .. method:: ShrinkBy(xFactor, yFactor) Return a version of the image scaled smaller by the given factors. **Parameters:** * `xFactor` (int) * `yFactor` (int) | **Returns:** `wx.Image `_ -------- .. method:: Size(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 use either the current mask colour if set or find, use, and set a suitable mask colour for any newly exposed areas. Returns the (modified) image itself. **Parameters:** * `size` (`wx.Size `_) * `pos` (`wx.Point `_) * `red` (int) * `green` (int) * `blue` (int) | **Returns:** `wx.Image `_ .. seealso:: `Resize <#Resize>`_ -------- Properties ^^^^^^^^^^ .. attribute:: AlphaBuffer See `GetAlphaBuffer <#GetAlphaBuffer>`_ and `SetAlphaBuffer <#SetAlphaBuffer>`_ .. attribute:: AlphaData See `GetAlphaData <#GetAlphaData>`_ and `SetAlphaData <#SetAlphaData>`_ .. attribute:: Data See `GetData <#GetData>`_ and `SetData <#SetData>`_ .. attribute:: DataBuffer See `GetDataBuffer <#GetDataBuffer>`_ and `SetDataBuffer <#SetDataBuffer>`_ .. attribute:: Height See `GetHeight <#GetHeight>`_ .. attribute:: MaskBlue See `GetMaskBlue <#GetMaskBlue>`_ .. attribute:: MaskGreen See `GetMaskGreen <#GetMaskGreen>`_ .. attribute:: MaskRed See `GetMaskRed <#GetMaskRed>`_ .. attribute:: Width See `GetWidth <#GetWidth>`_