.. include:: headings.inc .. _Image: ========================================================================================================================================== |phoenix_title| **Image** ========================================================================================================================================== This class encapsulates a platform-independent image. An image can be created from data, or using :meth:`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 :ref:`Image` cannot (currently) be drawn directly to a :ref:`DC`. Instead, a platform-specific :ref:`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 :meth:`DC.DrawBitmap` . More on the difference between :ref:`Image` and :ref:`Bitmap`: :ref:`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, :ref:`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 :ref:`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 :ref:`Mask` object associated to the bitmap object. |phoenix_title| Alpha channel support ===================================== Starting from wxWidgets 2.5.0 :ref:`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 :meth:`Image.GetAlpha` you should check if this image contains an alpha channel with :meth:`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 :meth:`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. |phoenix_title| Available image handlers ======================================== The following image handlers are available. BMPHandler is always installed by default. To use other image formats, install the appropriate handler with :meth:`Image.AddHandler` or call :func:`InitAllImageHandlers`. - BMPHandler: For loading (including alpha support) and saving, always installed. - PNGHandler: For loading and saving. Includes alpha support. - JPEGHandler: For loading and saving. - GIFHandler: For loading and saving (see below). - PCXHandler: For loading and saving (see below). - PNMHandler: For loading and saving (see below). - TIFFHandler: For loading and saving. Includes alpha support. - TGAHandler: For loading and saving. Includes alpha support. - IFFHandler: For loading only. - XPMHandler: For loading and saving. - ICOHandler: For loading and saving. - CURHandler: For loading and saving. - ANIHandler: For loading only. 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 :meth:`Image.ConvertAlphaToMask` ). Saving an animated ``GIF`` requires images of the same size (see `GIFHandler.SaveAnimation)` .. seealso:: :ref:`Bitmap`, :func:`InitAllImageHandlers`, `PixelData` | |class_hierarchy| Inheritance Diagram ===================================== Inheritance diagram for class **Image** .. raw:: html

Inheritance diagram of Image

| |method_summary| Methods Summary ================================ ================================================================================ ================================================================================ :meth:`~Image.__init__` Creates an empty :ref:`Image` object without an alpha channel. :meth:`~Image.AddHandler` Register an image handler. :meth:`~Image.AdjustChannels` This function muliplies all 4 channels (red, green, blue, alpha) with :meth:`~Image.Blur` Blurs the image in both horizontal and vertical directions by the specified pixel `blurRadius`. :meth:`~Image.BlurHorizontal` Blurs the image in the horizontal direction only. :meth:`~Image.BlurVertical` Blurs the image in the vertical direction only. :meth:`~Image.CanRead` Returns ``True`` if at least one of the available image handlers can read the file with the given name. :meth:`~Image.CleanUpHandlers` Deletes all image handlers. :meth:`~Image.Clear` Initialize the image data with zeroes (the default) or with the byte value given as `value`. :meth:`~Image.ClearAlpha` Removes the alpha channel from the image. :meth:`~Image.ComputeHistogram` Computes the histogram of the image. :meth:`~Image.ConvertAlphaToMask` If the image has alpha channel, this method converts it to mask. :meth:`~Image.ConvertToBitmap` ConvertToBitmap(depth=-1) -> Bitmap :meth:`~Image.ConvertToDisabled` Returns disabled (dimmed) version of the image. :meth:`~Image.ConvertToGreyscale` Returns a greyscale version of the image. :meth:`~Image.ConvertToMono` Returns monochromatic version of the image. :meth:`~Image.ConvertToMonoBitmap` ConvertToMonoBitmap(red, green, blue) -> Bitmap :meth:`~Image.Copy` Returns an identical copy of this image. :meth:`~Image.Create` Creates a fresh image. :meth:`~Image.Destroy` Destroys the image data. :meth:`~Image.FindFirstUnusedColour` Finds the first colour that is never used in the image. :meth:`~Image.FindHandler` Finds the handler with the given name. :meth:`~Image.FindHandlerMime` Finds the handler associated with the given ``MIME`` type. :meth:`~Image.GetAlpha` Return alpha value at given pixel location. :meth:`~Image.GetAlphaBuffer` Returns a writable Python buffer object that is pointing at the Alpha :meth:`~Image.GetBlue` Returns the blue intensity at the given coordinate. :meth:`~Image.GetDataBuffer` Returns a writable Python buffer object that is pointing at the ``RGB`` :meth:`~Image.GetGreen` Returns the green intensity at the given coordinate. :meth:`~Image.GetHeight` Gets the height of the image in pixels. :meth:`~Image.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. :meth:`~Image.GetImageExtWildcard` Iterates all registered :ref:`ImageHandler` objects, and returns a string containing file extension masks suitable for passing to file open/save dialog boxes. :meth:`~Image.GetMaskBlue` Gets the blue value of the mask colour. :meth:`~Image.GetMaskGreen` Gets the green value of the mask colour. :meth:`~Image.GetMaskRed` Gets the red value of the mask colour. :meth:`~Image.GetOption` Gets a user-defined string-valued option. :meth:`~Image.GetOptionInt` Gets a user-defined integer-valued option. :meth:`~Image.GetOrFindMaskColour` Get the current mask colour or find a suitable unused colour that could be used as a mask colour. :meth:`~Image.GetPalette` Returns the palette associated with the image. :meth:`~Image.GetRed` Returns the red intensity at the given coordinate. :meth:`~Image.GetSize` Returns the size of the image in pixels. :meth:`~Image.GetSubImage` Returns a sub image of the current one as long as the rect belongs entirely to the image. :meth:`~Image.GetType` Gets the type of image found by :meth:`LoadFile` or specified with :meth:`SaveFile` . :meth:`~Image.GetWidth` Gets the width of the image in pixels. :meth:`~Image.HSVtoRGB` Converts a color in ``HSV`` color space to ``RGB`` color space. :meth:`~Image.HasAlpha` Returns ``True`` if this image has alpha channel, ``False`` otherwise. :meth:`~Image.HasMask` Returns ``True`` if there is a mask active, ``False`` otherwise. :meth:`~Image.HasOption` Returns ``True`` if the given option is present. :meth:`~Image.InitAlpha` Initializes the image alpha channel data. :meth:`~Image.InitStandardHandlers` Internal use only. :meth:`~Image.InsertHandler` Adds a handler at the start of the static list of format handlers. :meth:`~Image.IsOk` Returns ``True`` if image data is present. :meth:`~Image.IsTransparent` Returns ``True`` if the given pixel is transparent, i.e. :meth:`~Image.LoadFile` Loads an image from an input stream. :meth:`~Image.Mirror` Returns a mirrored copy of the image. :meth:`~Image.Paste` Copy the data of the given `image` to the specified position in this image. :meth:`~Image.RGBtoHSV` Converts a color in ``RGB`` color space to ``HSV`` color space. :meth:`~Image.RemoveHandler` Finds the handler with the given name, and removes it. :meth:`~Image.Replace` Replaces the colour specified by `r1`,g1,b1 by the colour `r2`,g2,b2. :meth:`~Image.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. :meth:`~Image.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. :meth:`~Image.Rotate` Rotates the image about the given point, by `angle` radians. :meth:`~Image.Rotate180` Returns a copy of the image rotated by 180 degrees. :meth:`~Image.Rotate90` Returns a copy of the image rotated 90 degrees in the direction indicated by `clockwise`. :meth:`~Image.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. :meth:`~Image.SaveFile` Saves an image in the given stream. :meth:`~Image.Scale` Returns a scaled version of the image. :meth:`~Image.SetAlpha` Sets the alpha value for the given pixel. :meth:`~Image.SetAlphaBuffer` Sets the internal image alpha pointer to point at a Python buffer :meth:`~Image.SetData` Sets the image data without performing checks. :meth:`~Image.SetDataBuffer` Sets the internal image data pointer to point at a Python buffer :meth:`~Image.SetMask` Specifies whether there is a mask or not. :meth:`~Image.SetMaskColour` Sets the mask colour for this image (and tells the image to use the mask). :meth:`~Image.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. :meth:`~Image.SetOption` Sets a user-defined option. :meth:`~Image.SetPalette` Associates a palette with the image. :meth:`~Image.SetRGB` Sets the colour of the pixels within the given rectangle. :meth:`~Image.SetType` Set the type of image returned by :meth:`GetType` . :meth:`~Image.Size` Returns a resized version of this image without scaling it by adding either a border with the given colour or cropping as necessary. :meth:`~Image.__nonzero__` ================================================================================ ================================================================================ | |property_summary| Properties Summary ===================================== ================================================================================ ================================================================================ :attr:`~Image.Height` See :meth:`~Image.GetHeight` :attr:`~Image.MaskBlue` See :meth:`~Image.GetMaskBlue` :attr:`~Image.MaskGreen` See :meth:`~Image.GetMaskGreen` :attr:`~Image.MaskRed` See :meth:`~Image.GetMaskRed` :attr:`~Image.Type` See :meth:`~Image.GetType` and :meth:`~Image.SetType` :attr:`~Image.Width` See :meth:`~Image.GetWidth` ================================================================================ ================================================================================ | |api| Class API =============== .. class:: Image(Object) 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) .. method:: __init__(self, *args, **kw) |overload| **Overloaded Implementations**: **~~~** **__init__** `(self)` Creates an empty :ref:`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. :param `width`: Specifies the width of the image. :type `width`: int :param `height`: Specifies the height of the image. :type `height`: int :param `clear`: If ``True``, initialize the image to black. :type `clear`: bool **~~~** **__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. :param `sz`: :type `sz`: Size :param `clear`: :type `clear`: bool **~~~** **__init__** `(self, name, type=BITMAP_TYPE_ANY, index=-1)` Creates an image from a file. :param `name`: Name of the file from which to load the image. :type `name`: string :param `type`: May be one of the following: - ``BITMAP_TYPE_BMP``: Load a Windows bitmap file. - ``BITMAP_TYPE_GIF``: Load a ``GIF`` bitmap file. - ``BITMAP_TYPE_JPEG``: Load a ``JPEG`` bitmap file. - ``BITMAP_TYPE_PNG``: Load a ``PNG`` bitmap file. - ``BITMAP_TYPE_PCX``: Load a ``PCX`` bitmap file. - ``BITMAP_TYPE_PNM``: Load a ``PNM`` bitmap file. - ``BITMAP_TYPE_TIFF``: Load a ``TIFF`` bitmap file. - ``BITMAP_TYPE_TGA``: Load a ``TGA`` bitmap file. - ``BITMAP_TYPE_XPM``: Load a ``XPM`` bitmap file. - ``BITMAP_TYPE_ICO``: Load a Windows icon file (``ICO``). - ``BITMAP_TYPE_CUR``: Load a Windows cursor file (``CUR``). - ``BITMAP_TYPE_ANI``: Load a Windows animated cursor file (``ANI``). - ``BITMAP_TYPE_ANY``: Will try to autodetect the format. :type `type`: BitmapType :param `index`: 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. :type `index`: int .. 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 :meth:`Image.AddHandler` or InitAllImageHandlers. .. note:: You can use :meth:`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) .. seealso:: :meth:`LoadFile` **~~~** **__init__** `(self, name, mimetype, index=-1)` Creates an image from a file using MIME-types to specify the type. :param `name`: Name of the file from which to load the image. :type `name`: string :param `mimetype`: ``MIME`` type string (for example 'image/jpeg') :type `mimetype`: string :param `index`: See description in :ref:`Image` overload. :type `index`: int **~~~** **__init__** `(self, stream, type=BITMAP_TYPE_ANY, index=-1)` Creates an image from a stream. :param `stream`: Opened input stream from which to load the image. Currently, the stream must support seeking. :type `stream`: InputStream :param `type`: See description in :ref:`Image` overload. :type `type`: BitmapType :param `index`: See description in :ref:`Image` overload. :type `index`: int **~~~** **__init__** `(self, stream, mimetype, index=-1)` Creates an image from a stream using MIME-types to specify the type. :param `stream`: Opened input stream from which to load the image. Currently, the stream must support seeking. :type `stream`: InputStream :param `mimetype`: ``MIME`` type string (for example 'image/jpeg') :type `mimetype`: string :param `index`: See description in :ref:`Image` overload. :type `index`: int **~~~** **__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 **~~~** .. staticmethod:: AddHandler(handler) Register an image handler. Typical example of use: :: wx.Image.AddHandler(wx.PNGHandler) See :ref:`Available image handlers ` for a list of the available handlers. You can also use :func:`InitAllImageHandlers` to add handlers for all the image formats supported by wxWidgets at once. :param `handler`: A heap-allocated handler object which will be deleted by :ref:`Image` if it is removed later by :meth:`RemoveHandler` or at program shutdown. :type `handler`: ImageHandler .. method:: 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. :rtype: :ref:`Image` .. method:: 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. :param `blurRadius`: :type `blurRadius`: int :rtype: :ref:`Image` .. seealso:: :meth:`BlurHorizontal` , :meth:`BlurVertical` .. method:: BlurHorizontal(self, blurRadius) Blurs the image in the horizontal direction only. This should not be used when using a single mask colour for transparency. :param `blurRadius`: :type `blurRadius`: int :rtype: :ref:`Image` .. seealso:: :meth:`Blur` , :meth:`BlurVertical` .. method:: BlurVertical(self, blurRadius) Blurs the image in the vertical direction only. This should not be used when using a single mask colour for transparency. :param `blurRadius`: :type `blurRadius`: int :rtype: :ref:`Image` .. seealso:: :meth:`Blur` , :meth:`BlurHorizontal` .. staticmethod:: CanRead(*args, **kw) |overload| **Overloaded Implementations**: **~~~** **CanRead** `(filename)` Returns ``True`` if at least one of the available image handlers can read the file with the given name. See :meth:`ImageHandler.CanRead` for more info. :param `filename`: :type `filename`: string :rtype: `bool` **~~~** **CanRead** `(stream)` Returns ``True`` if at least one of the available image handlers can read the data in the given stream. See :meth:`ImageHandler.CanRead` for more info. :param `stream`: :type `stream`: InputStream :rtype: `bool` **~~~** .. staticmethod:: CleanUpHandlers() Deletes all image handlers. This function is called by wxWidgets on exit. .. method:: Clear(self, value=0) Initialize the image data with zeroes (the default) or with the byte value given as `value`. :param `value`: :type `value`: int .. versionadded:: 2.9.0 .. method:: ClearAlpha(self) Removes the alpha channel from the image. This function should only be called if the image has alpha channel data, use :meth:`HasAlpha` to check for this. .. versionadded:: 2.9.1 .. method:: ComputeHistogram(self, histogram) Computes the histogram of the image. `histogram` is a reference to :ref:`ImageHistogram` object. :ref:`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 :param `histogram`: :type `histogram`: ImageHistogram :rtype: `int` :returns: Returns number of colours in the histogram. .. method:: ConvertAlphaToMask(self, *args, **kw) |overload| **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 :meth:`FindFirstUnusedColour` by this function, see the overload below if you this is not appropriate. :param `threshold`: :type `threshold`: int :rtype: `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. :param `mr`: The red component of the mask colour. :type `mr`: int :param `mg`: The green component of the mask colour. :type `mg`: int :param `mb`: The blue component of the mask colour. :type `mb`: int :param `threshold`: 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. :type `threshold`: int :rtype: `bool` :returns: Returns ``True`` on success, ``False`` on error. .. versionadded:: 2.9.0 **~~~** .. method:: ConvertToBitmap(self, depth=-1) ConvertToBitmap(depth=-1) -> Bitmap Convert the image to a wx.Bitmap. .. method:: ConvertToDisabled(self, brightness=255) Returns disabled (dimmed) version of the image. :param `brightness`: :type `brightness`: int :rtype: :ref:`Image` .. versionadded:: 2.9.0 .. method:: ConvertToGreyscale(self, *args, **kw) |overload| **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`). :param `weight_r`: :type `weight_r`: float :param `weight_g`: :type `weight_g`: float :param `weight_b`: :type `weight_b`: float :rtype: :ref:`Image` **~~~** **ConvertToGreyscale** `(self)` Returns a greyscale version of the image. :rtype: :ref:`Image` .. versionadded:: 2.9.0 **~~~** .. method:: 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. :param `r`: :type `r`: int :param `g`: :type `g`: int :param `b`: :type `b`: int :rtype: :ref:`Image` .. method:: ConvertToMonoBitmap(self, red, green, blue) ConvertToMonoBitmap(red, green, blue) -> Bitmap Creates a monochrome version of the image and returns it as a wx.Bitmap. .. method:: Copy(self) Returns an identical copy of this image. :rtype: :ref:`Image` .. method:: Create(self, *args, **kw) |overload| **Overloaded Implementations**: **~~~** **Create** `(self, width, height, clear=True)` Creates a fresh image. See :meth:`Image.__init__` for more info. :param `width`: :type `width`: int :param `height`: :type `height`: int :param `clear`: :type `clear`: bool :rtype: `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. :param `sz`: :type `sz`: Size :param `clear`: :type `clear`: bool :rtype: `bool` **~~~** **Create** `(self, width, height, data)` :rtype: `bool` **~~~** **Create** `(self, width, height, data, alpha)` :rtype: `bool` **~~~** **Create** `(self, size, data)` :rtype: `bool` **~~~** **Create** `(self, size, data, alpha)` :rtype: `bool` **~~~** .. method:: Destroy(self) Destroys the image data. .. method:: 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. :param `startR`: :type `startR`: int :param `startG`: :type `startG`: int :param `startB`: :type `startB`: int :rtype: `tuple` :returns: ( `r`, `g`, `b` ) .. note:: This method involves computing the histogram, which is a computationally intensive operation. .. staticmethod:: FindHandler(*args, **kw) |overload| **Overloaded Implementations**: **~~~** **FindHandler** `(name)` Finds the handler with the given name. :param `name`: The handler name. :type `name`: string :rtype: :ref:`ImageHandler` :returns: A pointer to the handler if found, ``None`` otherwise. .. seealso:: :ref:`ImageHandler` **~~~** **FindHandler** `(extension, imageType)` Finds the handler associated with the given extension and type. :param `extension`: The file extension, such as "bmp". :type `extension`: string :param `imageType`: The image type; one of the :ref:`BitmapType` values. :type `imageType`: BitmapType :rtype: :ref:`ImageHandler` :returns: A pointer to the handler if found, ``None`` otherwise. .. seealso:: :ref:`ImageHandler` **~~~** **FindHandler** `(imageType)` Finds the handler associated with the given image type. :param `imageType`: The image type; one of the :ref:`BitmapType` values. :type `imageType`: BitmapType :rtype: :ref:`ImageHandler` :returns: A pointer to the handler if found, ``None`` otherwise. .. seealso:: :ref:`ImageHandler` **~~~** .. staticmethod:: FindHandlerMime(mimetype) Finds the handler associated with the given ``MIME`` type. :param `mimetype`: ``MIME`` type. :type `mimetype`: string :rtype: :ref:`ImageHandler` :returns: A pointer to the handler if found, ``None`` otherwise. .. seealso:: :ref:`ImageHandler` .. method:: GetAlpha(self, *args, **kw) |overload| **Overloaded Implementations**: **~~~** **GetAlpha** `(self, x, y)` Return alpha value at given pixel location. :param `x`: :type `x`: int :param `y`: :type `y`: int :rtype: `int` **~~~** **GetAlpha** `(self)` Returns a copy of the Alpha bytes of the image. :rtype: `PyObject` **~~~** .. method:: GetAlphaBuffer(self) 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. :rtype: `PyObject` .. method:: GetBlue(self, x, y) Returns the blue intensity at the given coordinate. :param `x`: :type `x`: int :param `y`: :type `y`: int :rtype: `int` .. method:: GetDataBuffer(self) 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. :rtype: `PyObject` .. method:: GetGreen(self, x, y) Returns the green intensity at the given coordinate. :param `x`: :type `x`: int :param `y`: :type `y`: int :rtype: `int` .. method:: GetHeight(self) Gets the height of the image in pixels. :rtype: `int` .. seealso:: :meth:`GetWidth` , :meth:`GetSize` .. staticmethod:: 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 :meth:`ImageHandler.GetImageCount` for more info. The parameter `type` may be one of the following values: - ``BITMAP_TYPE_BMP``: Load a Windows bitmap file. - ``BITMAP_TYPE_GIF``: Load a ``GIF`` bitmap file. - ``BITMAP_TYPE_JPEG``: Load a ``JPEG`` bitmap file. - ``BITMAP_TYPE_PNG``: Load a ``PNG`` bitmap file. - ``BITMAP_TYPE_PCX``: Load a ``PCX`` bitmap file. - ``BITMAP_TYPE_PNM``: Load a ``PNM`` bitmap file. - ``BITMAP_TYPE_TIFF``: Load a ``TIFF`` bitmap file. - ``BITMAP_TYPE_TGA``: Load a ``TGA`` bitmap file. - ``BITMAP_TYPE_XPM``: Load a ``XPM`` bitmap file. - ``BITMAP_TYPE_ICO``: Load a Windows icon file (``ICO``). - ``BITMAP_TYPE_CUR``: Load a Windows cursor file (``CUR``). - ``BITMAP_TYPE_ANI``: Load a Windows animated cursor file (``ANI``). - ``BITMAP_TYPE_ANY``: Will try to autodetect the format. :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). |overload| **Overloaded Implementations**: **~~~** **GetImageCount** `(filename, type=BITMAP_TYPE_ANY)` :param `filename`: :type `filename`: string :param `type`: :type `type`: BitmapType :rtype: `int` **~~~** **GetImageCount** `(stream, type=BITMAP_TYPE_ANY)` :param `stream`: :type `stream`: InputStream :param `type`: :type `type`: BitmapType :rtype: `int` **~~~** .. staticmethod:: GetImageExtWildcard() Iterates all registered :ref:`ImageHandler` objects, and returns a string containing file extension masks suitable for passing to file open/save dialog boxes. :rtype: `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) .. seealso:: :ref:`ImageHandler` .. method:: GetMaskBlue(self) Gets the blue value of the mask colour. :rtype: `int` .. method:: GetMaskGreen(self) Gets the green value of the mask colour. :rtype: `int` .. method:: GetMaskRed(self) Gets the red value of the mask colour. :rtype: `int` .. method:: 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 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. :param `name`: The name of the option, case-insensitive. :type `name`: string :rtype: `string` :returns: The value of the option or an empty string if not found. Use :meth:`HasOption` if an empty string can be a valid option value. .. seealso:: :meth:`SetOption` , :meth:`GetOptionInt` , :meth:`HasOption` .. method:: 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 :meth:`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 :meth:`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 :meth:`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. .. versionadded:: 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 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. An 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. An 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 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. :param `name`: The name of the option, case-insensitive. :type `name`: string :rtype: `int` :returns: The value of the option or 0 if not found. Use :meth:`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. .. seealso:: :meth:`SetOption` , :meth:`GetOption` .. method:: 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. :rtype: `tuple` :returns: ( `r`, `g`, `b` ) .. method:: GetPalette(self) Returns the palette associated with the image. Currently the palette is only used when converting to :ref:`Bitmap` under Windows. Some of the :ref:`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). :rtype: `Palette` .. method:: GetRed(self, x, y) Returns the red intensity at the given coordinate. :param `x`: :type `x`: int :param `y`: :type `y`: int :rtype: `int` .. method:: GetSize(self) Returns the size of the image in pixels. :rtype: :ref:`Size` .. versionadded:: 2.9.0 .. seealso:: :meth:`GetHeight` , :meth:`GetWidth` .. method:: GetSubImage(self, rect) Returns a sub image of the current one as long as the rect belongs entirely to the image. :param `rect`: :type `rect`: Rect :rtype: :ref:`Image` .. method:: GetType(self) Gets the type of image found by :meth:`LoadFile` or specified with :meth:`SaveFile` . :rtype: :ref:`BitmapType` .. versionadded:: 2.9.0 .. method:: GetWidth(self) Gets the width of the image in pixels. :rtype: `int` .. seealso:: :meth:`GetHeight` , :meth:`GetSize` .. staticmethod:: HSVtoRGB(hsv) Converts a color in ``HSV`` color space to ``RGB`` color space. :param `hsv`: :type `hsv`: HSVValue :rtype: :ref:`RGBValue` .. method:: HasAlpha(self) Returns ``True`` if this image has alpha channel, ``False`` otherwise. :rtype: `bool` .. seealso:: :meth:`GetAlpha` , :meth:`SetAlpha` .. method:: HasMask(self) Returns ``True`` if there is a mask active, ``False`` otherwise. :rtype: `bool` .. method:: 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 :meth:`GetOption` and :meth:`GetOptionInt` function docs. :param `name`: :type `name`: string :rtype: `bool` .. seealso:: :meth:`SetOption` , :meth:`GetOption` , :meth:`GetOptionInt` .. method:: 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. .. staticmethod:: InitStandardHandlers() Internal use only. Adds standard image format handlers. It only install BMPHandler for the time being, which is used by :ref:`Bitmap`. This function is called by wxWidgets on startup, and shouldn't be called by the user. .. seealso:: :ref:`ImageHandler`, :func:`InitAllImageHandlers`, `Quantize` .. staticmethod:: InsertHandler(handler) Adds a handler at the start of the static list of format handlers. :param `handler`: A new image format handler object. There is usually only one instance of a given handler class in an application session. :type `handler`: ImageHandler .. seealso:: :ref:`ImageHandler` .. method:: IsOk(self) Returns ``True`` if image data is present. :rtype: `bool` .. method:: 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`. :param `x`: :type `x`: int :param `y`: :type `y`: int :param `threshold`: :type `threshold`: int :rtype: `bool` .. method:: LoadFile(self, *args, **kw) |overload| **Overloaded Implementations**: **~~~** **LoadFile** `(self, stream, type=BITMAP_TYPE_ANY, index=-1)` Loads an image from an input stream. :param `stream`: Opened input stream from which to load the image. Currently, the stream must support seeking. :type `stream`: InputStream :param `type`: May be one of the following: - ``BITMAP_TYPE_BMP``: Load a Windows bitmap file. - ``BITMAP_TYPE_GIF``: Load a ``GIF`` bitmap file. - ``BITMAP_TYPE_JPEG``: Load a ``JPEG`` bitmap file. - ``BITMAP_TYPE_PNG``: Load a ``PNG`` bitmap file. - ``BITMAP_TYPE_PCX``: Load a ``PCX`` bitmap file. - ``BITMAP_TYPE_PNM``: Load a ``PNM`` bitmap file. - ``BITMAP_TYPE_TIFF``: Load a ``TIFF`` bitmap file. - ``BITMAP_TYPE_TGA``: Load a ``TGA`` bitmap file. - ``BITMAP_TYPE_XPM``: Load a ``XPM`` bitmap file. - ``BITMAP_TYPE_ICO``: Load a Windows icon file (``ICO``). - ``BITMAP_TYPE_CUR``: Load a Windows cursor file (``CUR``). - ``BITMAP_TYPE_ANI``: Load a Windows animated cursor file (``ANI``). - ``BITMAP_TYPE_ANY``: Will try to autodetect the format. :type `type`: BitmapType :param `index`: 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. :type `index`: int :rtype: `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 :func:`LogError` takes place. .. note:: Depending on how wxWidgets has been configured, not all formats may be available. .. note:: You can use :meth:`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) .. seealso:: :meth:`SaveFile` **~~~** **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. :param `name`: Name of the file from which to load the image. :type `name`: string :param `type`: See the description in the :meth:`LoadFile` overload. :type `type`: BitmapType :param `index`: See the description in the :meth:`LoadFile` overload. :type `index`: int :rtype: `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. :param `name`: Name of the file from which to load the image. :type `name`: string :param `mimetype`: ``MIME`` type string (for example 'image/jpeg') :type `mimetype`: string :param `index`: See the description in the :meth:`LoadFile` overload. :type `index`: int :rtype: `bool` **~~~** **LoadFile** `(self, stream, mimetype, index=-1)` Loads an image from an input stream. :param `stream`: Opened input stream from which to load the image. Currently, the stream must support seeking. :type `stream`: InputStream :param `mimetype`: ``MIME`` type string (for example 'image/jpeg') :type `mimetype`: string :param `index`: See the description in the :meth:`LoadFile` overload. :type `index`: int :rtype: `bool` **~~~** .. method:: Mirror(self, horizontally=True) Returns a mirrored copy of the image. The parameter `horizontally` indicates the orientation. :param `horizontally`: :type `horizontally`: bool :rtype: :ref:`Image` .. method:: Paste(self, image, x, y) Copy the data of the given `image` to the specified position in this image. :param `image`: :type `image`: Image :param `x`: :type `x`: int :param `y`: :type `y`: int .. staticmethod:: RGBtoHSV(rgb) Converts a color in ``RGB`` color space to ``HSV`` color space. :param `rgb`: :type `rgb`: RGBValue :rtype: :ref:`HSVValue` .. staticmethod:: RemoveHandler(name) Finds the handler with the given name, and removes it. The handler is also deleted. :param `name`: The handler name. :type `name`: string :rtype: `bool` :returns: ``True`` if the handler was found and removed, ``False`` otherwise. .. seealso:: :ref:`ImageHandler` .. method:: Replace(self, r1, g1, b1, r2, g2, b2) Replaces the colour specified by `r1`,g1,b1 by the colour `r2`,g2,b2. :param `r1`: :type `r1`: int :param `g1`: :type `g1`: int :param `b1`: :type `b1`: int :param `r2`: :type `r2`: int :param `g2`: :type `g2`: int :param `b2`: :type `b2`: int .. method:: 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 :meth:`Scale` function. Returns the (modified) image itself. :param `width`: :type `width`: int :param `height`: :type `height`: int :param `quality`: :type `quality`: ImageResizeQuality :rtype: :ref:`Image` .. seealso:: :meth:`Scale` .. method:: 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. :param `size`: :type `size`: Size :param `pos`: :type `pos`: Point :param `red`: :type `red`: int :param `green`: :type `green`: int :param `blue`: :type `blue`: int :rtype: :ref:`Image` :returns: The (modified) image itself. .. seealso:: :meth:`Size` .. method:: 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. :param `angle`: :type `angle`: float :param `rotationCentre`: :type `rotationCentre`: Point :param `interpolating`: :type `interpolating`: bool :param `offsetAfterRotation`: :type `offsetAfterRotation`: Point :rtype: :ref:`Image` .. method:: Rotate180(self) Returns a copy of the image rotated by 180 degrees. :rtype: :ref:`Image` .. versionadded:: 2.9.2 .. method:: Rotate90(self, clockwise=True) Returns a copy of the image rotated 90 degrees in the direction indicated by `clockwise`. :param `clockwise`: :type `clockwise`: bool :rtype: :ref:`Image` .. method:: RotateHue(self, angle) 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. :param `angle`: :type `angle`: float .. method:: SaveFile(self, *args, **kw) |overload| **Overloaded Implementations**: **~~~** **SaveFile** `(self, stream, mimetype)` Saves an image in the given stream. :param `stream`: Opened output stream to save the image to. :type `stream`: OutputStream :param `mimetype`: ``MIME`` type. :type `mimetype`: string :rtype: `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 :meth:`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) .. seealso:: :meth:`LoadFile` **~~~** **SaveFile** `(self, name, type)` Saves an image in the named file. :param `name`: Name of the file to save the image to. :type `name`: string :param `type`: Currently these types can be used: - ``BITMAP_TYPE_BMP``: Save a ``BMP`` image file. - ``BITMAP_TYPE_JPEG``: Save a ``JPEG`` image file. - ``BITMAP_TYPE_PNG``: Save a ``PNG`` image file. - ``BITMAP_TYPE_PCX``: Save a ``PCX`` image file (tries to save as 8-bit if possible, falls back to 24-bit otherwise). - ``BITMAP_TYPE_PNM``: Save a ``PNM`` image file (as raw ``RGB`` always). - ``BITMAP_TYPE_TIFF``: Save a ``TIFF`` image file. - ``BITMAP_TYPE_XPM``: Save a ``XPM`` image file. - ``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. - ``BITMAP_TYPE_CUR``: Save a Windows cursor file (``CUR``). :type `type`: BitmapType :rtype: `bool` **~~~** **SaveFile** `(self, name, mimetype)` Saves an image in the named file. :param `name`: Name of the file to save the image to. :type `name`: string :param `mimetype`: ``MIME`` type. :type `mimetype`: string :rtype: `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. :param `name`: Name of the file to save the image to. :type `name`: string :rtype: `bool` **~~~** **SaveFile** `(self, stream, type)` Saves an image in the given stream. :param `stream`: Opened output stream to save the image to. :type `stream`: OutputStream :param `type`: ``MIME`` type. :type `type`: BitmapType :rtype: `bool` **~~~** .. method:: 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 :ref:`MemoryDC` into another :ref:`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) :param `width`: :type `width`: int :param `height`: :type `height`: int :param `quality`: :type `quality`: ImageResizeQuality :rtype: :ref:`Image` .. seealso:: :meth:`Rescale` .. method:: SetAlpha(self, *args, **kw) |overload| **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 :meth:`HasAlpha` to check for this. :param `x`: :type `x`: int :param `y`: :type `y`: int :param `alpha`: :type `alpha`: int **~~~** **SetAlpha** `(self, alpha)` **~~~** .. method:: 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 wx.Image does. .. method:: SetData(self, *args, **kw) |overload| **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 :ref:`Image` object, that will be responsible for deleting it. Do not pass to this function a pointer obtained through :meth:`GetData` . **~~~** **SetData** `(self, data, new_width, new_height)` **~~~** .. method:: 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 wx.Image does. |overload| **Overloaded Implementations**: **~~~** **SetDataBuffer** `(self, data)` **~~~** **SetDataBuffer** `(self, data, new_width, new_height)` **~~~** .. method:: SetMask(self, hasMask=True) Specifies whether there is a mask or not. The area of the mask is determined by the current mask colour. :param `hasMask`: :type `hasMask`: bool .. method:: SetMaskColour(self, red, green, blue) Sets the mask colour for this image (and tells the image to use the mask). :param `red`: :type `red`: int :param `green`: :type `green`: int :param `blue`: :type `blue`: int .. method:: 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. :param `mask`: :type `mask`: Image :param `mr`: :type `mr`: int :param `mg`: :type `mg`: int :param `mb`: :type `mb`: int :rtype: `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. .. method:: SetOption(self, *args, **kw) |overload| **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 :meth:`GetOption` and :meth:`GetOptionInt` function docs. :param `name`: :type `name`: string :param `value`: :type `value`: string .. seealso:: :meth:`GetOption` , :meth:`GetOptionInt` , :meth:`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. :param `name`: :type `name`: string :param `value`: :type `value`: int **~~~** .. method:: SetPalette(self, palette) Associates a palette with the image. The palette may be used when converting :ref:`Image` to :ref:`Bitmap` (MSW only at present) or in file save operations (none as yet). :param `palette`: :type `palette`: Palette .. method:: 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. :param `rect`: :type `rect`: Rect :param `red`: :type `red`: int :param `green`: :type `green`: int :param `blue`: :type `blue`: int .. method:: SetType(self, type) Set the type of image returned by :meth:`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 :meth:`LoadFile` (which would set the type correctly automatically). Notice that the image must be created before this function is called. :param `type`: 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. :type `type`: BitmapType .. versionadded:: 2.9.0 .. method:: 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. :param `size`: :type `size`: Size :param `pos`: :type `pos`: Point :param `red`: :type `red`: int :param `green`: :type `green`: int :param `blue`: :type `blue`: int :rtype: :ref:`Image` .. seealso:: :meth:`Resize` .. method:: __nonzero__(self) :rtype: `int` .. attribute:: Height See :meth:`~Image.GetHeight` .. attribute:: MaskBlue See :meth:`~Image.GetMaskBlue` .. attribute:: MaskGreen See :meth:`~Image.GetMaskGreen` .. attribute:: MaskRed See :meth:`~Image.GetMaskRed` .. attribute:: Type See :meth:`~Image.GetType` and :meth:`~Image.SetType` .. attribute:: Width See :meth:`~Image.GetWidth`