wx._core.Image
A platform-independent image class. An image can be created from
data, or using `wx.Bitmap.ConvertToImage`, or loaded from a file in a
variety of formats. Functions are available to set and get image
bits, so it can be used for basic image manipulation.
A wx.Image cannot be drawn directly to a `wx.DC`. Instead, a
platform-specific `wx.Bitmap` object must be created from it using the
`wx.BitmapFromImage` constructor. 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` you should check if this image contains an alpha channel
with `HasAlpha`. Note that currently only images loaded from PNG files
with transparency information will have an alpha channel.
AddHandler
AddHandler(ImageHandler handler)
CanRead
CanRead(String filename) -> bool
Returns True if the image handlers can read this file.
CanReadStream
CanReadStream(InputStream stream) -> bool
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.
ComputeHistogram(args, kwargs)
ComputeHistogram(self, ImageHistogram h) -> unsigned long
ConvertAlphaToMask(args, kwargs)
ConvertAlphaToMask(self, byte threshold=IMAGE_ALPHA_THRESHOLD) -> bool
If the image has alpha channel, this method converts it to mask. All
pixels with alpha value less than ``threshold`` are replaced with the
mask colour and the alpha channel is removed. The mask colour is
chosen automatically using `FindFirstUnusedColour`.
If the image image doesn't have alpha channel, ConvertAlphaToMask does
nothing.
ConvertColourToAlpha(args, kwargs)
ConvertColourToAlpha(self, byte r, byte g, byte b) -> bool
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.
ConvertToBitmap(args, kwargs)
ConvertToBitmap(self, int depth=-1) -> Bitmap
ConvertToMono(args, kwargs)
ConvertToMono(self, byte r, byte g, byte b) -> Image
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.
ConvertToMonoBitmap(args, kwargs)
ConvertToMonoBitmap(self, byte red, byte green, byte blue) -> Bitmap
Copy(args, kwargs)
Copy(self) -> Image
Returns an identical copy of the image.
CountColours(args, kwargs)
CountColours(self, unsigned long stopafter=(unsigned long) -1) -> unsigned long
Create(args, kwargs)
Create(self, int width, int height, bool 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.
Destroy(args, kwargs)
Destroy(self)
Destroys the image data.
FindFirstUnusedColour(args, kwargs)
FindFirstUnusedColour(int startR=1, int startG=0, int startB=0) -> (success, r, g, b)
Find first colour that is not used in the image and has higher RGB
values than startR, startG, startB. Returns a tuple consisting of a
success flag and rgb values.
GetAlpha(args, kwargs)
GetAlpha(self, int x, int y) -> byte
Returns the alpha value for the given pixel. This function may only be
called for the images with alpha channel, use `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.
GetAlphaBuffer(args, kwargs)
GetAlphaBuffer(self) -> PyObject
GetAlphaData(args, kwargs)
GetAlphaData(self) -> PyObject
Returns a string containing a copy of the alpha bytes of the image.
GetBlue(args, kwargs)
GetBlue(self, int x, int y) -> byte
Returns the blue intensity at the given coordinate.
GetData(args, kwargs)
GetData(self) -> PyObject
Returns a string containing a copy of the RGB bytes of the image.
GetDataBuffer(args, kwargs)
GetDataBuffer(self) -> PyObject
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.
GetGreen(args, kwargs)
GetGreen(self, int x, int y) -> byte
Returns the green intensity at the given coordinate.
GetHeight(args, kwargs)
GetHeight(self) -> int
Gets the height of the image in pixels.
GetImageCount
GetImageCount(String filename, long type=BITMAP_TYPE_ANY) -> int
If the image file contains more than one image and the image handler
is capable of retrieving these individually, this function will return
the number of available images.
GetImageExtWildcard
GetImageExtWildcard() -> String
Iterates all registered wxImageHandler objects, and returns a string
containing file extension masks suitable for passing to file open/save
dialog boxes.
GetMaskBlue(args, kwargs)
GetMaskBlue(self) -> byte
Gets the blue component of the mask colour.
GetMaskGreen(args, kwargs)
GetMaskGreen(self) -> byte
Gets the green component of the mask colour.
GetMaskRed(args, kwargs)
GetMaskRed(self) -> byte
Gets the red component of the mask colour.
GetOption(args, kwargs)
GetOption(self, String name) -> String
Gets the value of an image handler option.
GetOptionInt(args, kwargs)
GetOptionInt(self, String name) -> int
Gets the value of an image handler option as an integer. If the given
option is not present, the function returns 0.
GetOrFindMaskColour(args, kwargs)
GetOrFindMaskColour() -> (r,g,b)
Get the current mask colour or find a suitable colour.
GetRed(args, kwargs)
GetRed(self, int x, int y) -> byte
Returns the red intensity at the given coordinate.
GetSize(args, kwargs)
GetSize(self) -> Size
Returns the size of the image in pixels.
GetSubImage(args, kwargs)
GetSubImage(self, Rect rect) -> Image
Returns a sub image of the current one as long as the rect belongs
entirely to the image.
GetWidth(args, kwargs)
GetWidth(self) -> int
Gets the width of the image in pixels.
HasAlpha(args, kwargs)
HasAlpha(self) -> bool
Returns true if this image has alpha channel, false otherwise.
HasMask(args, kwargs)
HasMask(self) -> bool
Returns ``True`` if there is a mask active, ``False`` otherwise.
HasOption(args, kwargs)
HasOption(self, String name) -> bool
Returns true if the given option is present.
InitAlpha(args, kwargs)
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 a mask colour, all mask pixels will be completely transparent.
InsertHandler
InsertHandler(ImageHandler handler)
IsTransparent(args, kwargs)
IsTransparent(self, int x, int y, byte threshold=IMAGE_ALPHA_THRESHOLD) -> bool
Returns ``True`` if this pixel is masked or has an alpha value less
than the spcified threshold.
LoadFile(args, kwargs)
LoadFile(self, String name, long type=BITMAP_TYPE_ANY, int index=-1) -> bool
Loads an image from a file. If no handler type is provided, the
library will try to autodetect the format.
LoadMimeFile(args, kwargs)
LoadMimeFile(self, String name, String mimetype, int index=-1) -> bool
Loads an image from a file, specifying the image type with a MIME type
string.
LoadMimeStream(args, kwargs)
LoadMimeStream(self, InputStream stream, String mimetype, int index=-1) -> bool
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.
LoadStream(args, kwargs)
LoadStream(self, InputStream stream, long type=BITMAP_TYPE_ANY, int index=-1) -> bool
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.
Mirror(args, kwargs)
Mirror(self, bool horizontally=True) -> Image
Returns a mirrored copy of the image. The parameter ``horizontally``
indicates the orientation.
Ok(args, kwargs)
Ok(self) -> bool
Returns true if image data is present.
Paste(args, kwargs)
Paste(self, Image image, int x, int y)
Pastes ``image`` into this instance and takes care of the mask colour
and any out of bounds problems.
RemoveHandler
RemoveHandler(String name) -> bool
Replace(args, kwargs)
Replace(self, byte r1, byte g1, byte b1, byte r2, byte g2, byte b2)
Replaces the colour specified by ``(r1,g1,b1)`` by the colour
``(r2,g2,b2)``.
Rescale(args, kwargs)
Rescale(self, int width, int height) -> Image
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.
Returns the (modified) image itself.
Resize(args, kwargs)
Resize(self, Size size, Point pos, int r=-1, int g=-1, int b=-1) -> Image
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.
Rotate(args, kwargs)
Rotate(self, double angle, Point centre_of_rotation, bool interpolating=True,
Point offset_after_rotation=None) -> Image
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. Otherwise, black
will be used as the fill colour.
Returns the rotated image, leaving this image intact.
Rotate90(args, kwargs)
Rotate90(self, bool clockwise=True) -> Image
Returns a copy of the image rotated 90 degrees in the direction
indicated by ``clockwise``.
SaveFile(args, kwargs)
SaveFile(self, String name, int type) -> bool
Saves an image in the named file.
SaveMimeFile(args, kwargs)
SaveMimeFile(self, String name, String mimetype) -> bool
Saves an image in the named file.
Scale(args, kwargs)
Scale(self, int width, int height) -> Image
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`.
SetAlpha(args, kwargs)
SetAlpha(self, int x, int y, byte alpha)
Sets the alpha value for the given pixel. This function should only be
called if the image has alpha channel data, use `HasAlpha` to check
for this.
SetAlphaBuffer(args, kwargs)
SetAlphaBuffer(self, buffer alpha)
SetAlphaData(args, kwargs)
SetAlphaData(self, buffer 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.
SetData(args, kwargs)
SetData(self, buffer data)
Resets the Image's RGB data from a buffer of RGB bytes. Accepts
either a string or a buffer object holding the data and the length of
the data must be width*height*3.
SetDataBuffer(args, kwargs)
SetDataBuffer(self, buffer 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.
SetMask(args, kwargs)
SetMask(self, bool mask=True)
Specifies whether there is a mask or not. The area of the mask is
determined by the current mask colour.
SetMaskColour(args, kwargs)
SetMaskColour(self, byte r, byte g, byte b)
Sets the mask colour for this image (and tells the image to use the
mask).
SetMaskFromImage(args, kwargs)
SetMaskFromImage(self, Image mask, byte mr, byte mg, byte mb) -> bool
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.
Note that this method involves computing the histogram, which is
computationally intensive operation.
SetOption(args, kwargs)
SetOption(self, String name, String value)
Sets an image handler defined option. For example, when saving as a
JPEG file, the option ``wx.IMAGE_OPTION_QUALITY`` is used, which is a
number between 0 and 100 (0 is terrible, 100 is very good).
SetOptionInt(args, kwargs)
SetOptionInt(self, String name, int value)
Sets an image option as an integer.
SetRGB(args, kwargs)
SetRGB(self, int x, int y, byte r, byte g, byte b)
Sets the pixel at the given coordinate. This routine performs
bounds-checks for the coordinate so it can be considered a safe way to
manipulate the data, but in some cases this might be too slow so that
the data will have to be set directly. In that case you will have to
get access to the image data using the `GetData` method.
SetRGBRect(args, kwargs)
SetRGBRect(self, Rect rect, byte r, byte g, byte 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.
ShrinkBy(args, kwargs)
ShrinkBy(self, int xFactor, int yFactor) -> Image
Return a version of the image scaled smaller by the given factors.
Size(args, kwargs)
Size(self, Size size, Point pos, int r=-1, int g=-1, int b=-1) -> Image
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.
[constructor]
Usage: classname(arguments)
[member '__doc__']
Documentation for this class
[member '__module__']
The module that this class belongs to
[operator 'del']
Usage: del a
[operator 'nonzero']
Usage: None, used by core for things such as the not operator
[operator 'repr']
Usage: repr(a)