Home | Trees | Index | Help |
|
---|
Package wx :: Class Image |
|
object
--+ |Object
--+ | 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.
Method Summary | |
---|---|
Image |
|
__del__(self)
| |
__nonzero__(self)
| |
AddHandler(handler)
(Static method) | |
Image |
Blurs the image in both horizontal and vertical directions by the specified pixel radius. |
Image |
Blurs the image in the horizontal direction only. |
Image |
Blurs the image in the vertical direction only. |
bool |
Returns True if the image handlers can read this file. (Static method) |
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. (Static method) |
unsigned long | ComputeHistogram(self,
h)
|
bool |
If the image has alpha channel, this method converts it to mask. |
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. |
Bitmap | ConvertToBitmap(self,
depth)
|
Image |
Convert to greyscale image. |
Image |
Returns monochromatic version of the image. |
Bitmap | ConvertToMonoBitmap(self,
red,
green,
blue)
|
Image |
Returns an identical copy of the image. |
CountColours(self, unsigned long stopafter=(unsigned long) -1) -> unsigned long | |
Creates a fresh image. | |
Destroys the image data. | |
(success, r, g, b) |
Find first colour that is not used in the image and has higher RGB values than startR, startG, startB. |
byte |
Returns the alpha value for the given pixel. |
PyObject |
Returns a writable Python buffer object that is pointing at the Alpha data buffer inside the wx.Image. |
PyObject |
Returns a string containing a copy of the alpha bytes of the image. |
byte |
Returns the blue intensity at the given coordinate. |
PyObject |
Returns a string containing a copy of the RGB bytes of the image. |
PyObject |
Returns a writable Python buffer object that is pointing at the RGB image data buffer inside the wx.Image. |
byte |
Returns the green intensity at the given coordinate. |
PyObject | GetHandlers()
(Static method) |
int |
Gets the height of the image in pixels. |
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. (Static method) |
String |
Iterates all registered wxImageHandler objects, and returns a string containing file extension masks suitable for passing to file open/save dialog boxes. (Static method) |
byte |
Gets the blue component of the mask colour. |
byte |
Gets the green component of the mask colour. |
byte |
Gets the red component of the mask colour. |
String |
Gets the value of an image handler option. |
int |
Gets the value of an image handler option as an integer. |
(r,g,b) |
Get the current mask colour or find a suitable colour. |
byte |
Returns the red intensity at the given coordinate. |
Size |
Returns the size of the image in pixels. |
Image |
Returns a sub image of the current one as long as the rect belongs entirely to the image. |
int |
Gets the width of the image in pixels. |
bool |
Returns true if this image has alpha channel, false otherwise. |
bool |
Returns True if there is a mask active, False otherwise. |
bool |
Returns true if the given option is present. |
Image_RGBValue |
Converts a color in HSV color space to RGB color space. (Static method) |
Initializes the image alpha channel data. | |
InsertHandler(handler)
(Static method) | |
bool |
Returns true if image data is present. |
bool |
Returns True if this pixel is masked or has an alpha value less than the spcified threshold. |
bool |
Loads an image from a file. |
bool |
Loads an image from a file, specifying the image type with a MIME type string. |
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. |
bool |
Loads an image from an input stream or a readable Python file-like object. |
Image |
Returns a mirrored copy of the image. |
bool |
Returns true if image data is present. |
Pastes image into this instance and takes care of the mask colour and any out of bounds problems. | |
bool | RemoveHandler(name)
(Static method) |
Replaces the colour specified by (r1,g1,b1) by the colour (r2,g2,b2). | |
Image | ResampleBicubic(self,
width,
height)
|
Image | ResampleBox(self,
width,
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. |
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. |
Image_HSVValue |
Converts a color in RGB color space to HSV color space. (Static method) |
Image |
Rotates the image about the given point, by angle radians. |
Image |
Returns a copy of the image rotated 90 degrees in the direction indicated by clockwise. |
Rotates the hue of each pixel of the image. | |
bool |
Saves an image in the named file. |
bool |
Saves an image in the named file. |
Image |
Returns a scaled version of the image. |
Sets the alpha value for the given pixel. | |
Sets the internal image alpha pointer to point at a Python buffer object. | |
Resets the Image's alpha data from a buffer of bytes. | |
Resets the Image's RGB data from a buffer of RGB bytes. | |
Sets the internal image data pointer to point at a Python buffer object. | |
Specifies whether there is a mask or not. | |
Sets the mask colour for this image (and tells the image to use the mask). | |
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. |
Sets an image handler defined option. | |
Sets an image option as an integer. | |
Sets the pixel at the given coordinate. | |
Sets the colour of the pixels within the given rectangle. | |
Image |
Return a version of the image scaled smaller by the given factors. |
Image |
Returns a resized version of this image without scaling it by adding either a border with the given colour or cropping as necessary. |
Property Summary | |
---|---|
AlphaBuffer : See GetAlphaBuffer and SetAlphaBuffer | |
AlphaData : See GetAlphaData and SetAlphaData | |
Data : See GetData and SetData | |
DataBuffer : See GetDataBuffer and SetDataBuffer | |
Height : See GetHeight | |
MaskBlue : See GetMaskBlue | |
MaskGreen : See GetMaskGreen | |
MaskRed : See GetMaskRed | |
thisown : The membership flag | |
Width : See GetWidth |
Instance Method Details |
---|
__init__(self,
name,
type=BITMAP_TYPE_ANY,
index=-1)
|
wx.BITMAP_TYPE_BMP | Load a Windows bitmap file. |
wx.BITMAP_TYPE_GIF | Load a GIF bitmap file. |
wx.BITMAP_TYPE_JPEG | Load a JPEG bitmap file. |
wx.BITMAP_TYPE_PNG | Load a PNG bitmap file. |
wx.BITMAP_TYPE_PCX | Load a PCX bitmap file. |
wx.BITMAP_TYPE_PNM | Load a PNM bitmap file. |
wx.BITMAP_TYPE_TIF | Load a TIFF bitmap file. |
wx.BITMAP_TYPE_XPM | Load a XPM bitmap file. |
wx.BITMAP_TYPE_ICO | Load a Windows icon file (ICO). |
wx.BITMAP_TYPE_CUR | Load a Windows cursor file (CUR). |
wx.BITMAP_TYPE_ANI | Load a Windows animated cursor file (ANI). |
wx.BITMAP_TYPE_ANY | Will try to autodetect the format. |
index
-
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.
wx.Object.__init__
See Also:
wx.ImageFromMime
, wx.ImageFromStream
, wx.ImageFromStreamMime
,
wx.EmptyImage
, wx.ImageFromBitmap
, wx.ImageFromBuffer
,
wx.ImageFromData
, wx.ImageFromDataWithAlpha
Blur(self, radius)Blurs the image in both horizontal and vertical directions by the specified pixel radius. This should not be used when using a single mask colour for transparency.
|
BlurHorizontal(self, radius)Blurs the image in the horizontal direction only. This should not be used when using a single mask colour for transparency.
|
BlurVertical(self, radius)Blurs the image in the vertical direction only. This should not be used when using a single mask colour for transparency.
|
ConvertAlphaToMask(self, threshold=IMAGE_ALPHA_THRESHOLD)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 If the image image doesn't have alpha channel, ConvertAlphaToMask does nothing.
|
ConvertColourToAlpha(self, 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.
|
ConvertToGreyscale(self, lr=0.299, lg=0.587, lb=0.114)Convert to greyscale image. Uses the luminance component (Y) of the image. The luma value (YUV) is calculated using (R * lr) + (G * lg) + (B * lb), defaults to ITU-T BT.601
|
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.
|
Copy(self)Returns an identical copy of the image.
|
CountColours(*args, **kwargs)CountColours(self, unsigned long stopafter=(unsigned long) -1) -> unsigned long |
Create(self, 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.
|
Destroy(self)Destroys the image data.
|
FindFirstUnusedColour(startR=1, startG=0, startB=0)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(self, x, y)Returns the alpha value for the given pixel. This function may only be
called for the images with alpha channel, use 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(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.
|
GetAlphaData(self)Returns a string containing a copy of the alpha bytes of the image.
|
GetBlue(self, x, y)Returns the blue intensity at the given coordinate.
|
GetData(self)Returns a string containing a copy of the RGB bytes of the image.
|
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.
|
GetGreen(self, x, y)Returns the green intensity at the given coordinate.
|
GetHeight(self)Gets the height of the image in pixels.
|
GetMaskBlue(self)Gets the blue component of the mask colour.
|
GetMaskGreen(self)Gets the green component of the mask colour.
|
GetMaskRed(self)Gets the red component of the mask colour.
|
GetOption(self, name)Gets the value of an image handler option.
|
GetOptionInt(self, name)Gets the value of an image handler option as an integer. If the given option is not present, the function returns 0.
|
GetOrFindMaskColour()Get the current mask colour or find a suitable colour.
|
GetRed(self, x, y)Returns the red intensity at the given coordinate.
|
GetSize(self)Returns the size of the image in pixels.
|
GetSubImage(self, rect)Returns a sub image of the current one as long as the rect belongs entirely to the image.
|
GetWidth(self)Gets the width of the image in pixels.
|
HasAlpha(self)Returns true if this image has alpha channel, false otherwise. |
HasMask(self)Returns True if there is a mask active, False otherwise.
|
HasOption(self, name)Returns true if the given option is present.
|
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. |
IsOk(self)Returns true if image data is present.
|
IsTransparent(self, x, y, threshold=IMAGE_ALPHA_THRESHOLD)Returns True if this pixel is masked or has an alpha value less than the spcified threshold.
|
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.
|
LoadMimeFile(self, name, mimetype, index=-1)Loads an image from a file, specifying the image type with a MIME type string.
|
LoadMimeStream(self, 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.
|
LoadStream(self, stream, type=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.
|
Mirror(self, horizontally=True)Returns a mirrored copy of the image. The parameter horizontally indicates the orientation.
|
Ok(self)Returns true if image data is present.
|
Paste(self, image, x, y)Pastes image into this instance and takes care of the mask colour and any out of bounds problems.
|
Replace(self, r1, g1, b1, r2, g2, b2)Replaces the colour specified by (r1,g1,b1) by the colour (r2,g2,b2).
|
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. Returns the (modified) image itself.
|
Resize(self, size, pos, r=-1, g=-1, b=-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.
|
Rotate(self, 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. Otherwise, black will be used as the fill colour. Returns the rotated image, leaving this image intact.
|
Rotate90(self, clockwise=True)Returns a copy of the image rotated 90 degrees in the direction indicated by clockwise.
|
RotateHue(self, angle)Rotates the hue of each pixel of the image. Hue is a double in the range -1.0..1.0 where -1.0 is -360 degrees and 1.0 is 360 degrees
|
SaveFile(self, name, type)Saves an image in the named file.
|
SaveMimeFile(self, name, mimetype)Saves an image in the named file.
|
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
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.
|
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
|
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 as long as the wx.Image does.
|
SetAlphaData(self, 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(self, 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(self, 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(self, mask=True)Specifies whether there is a mask or not. The area of the mask is determined by the current mask colour.
|
SetMaskColour(self, r, g, b)Sets the mask colour for this image (and tells the image to use the mask).
|
SetMaskFromImage(self, mask, mr, mg, mb)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(self, name, 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(self, name, value)Sets an image option as an integer.
|
SetRGB(self, x, y, r, g, 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
|
SetRGBRect(self, 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.
|
ShrinkBy(self, xFactor, yFactor)Return a version of the image scaled smaller by the given factors.
|
Size(self, size, pos, r=-1, g=-1, b=-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.
|
Static Method Details |
---|
CanRead(filename)Returns True if the image handlers can read this file.
|
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.
|
GetImageCount(filename, type=BITMAP_TYPE_ANY)If the image file contains more than one image and the image handler is capable of retrieving these individually, this function will return the number of available images.
|
GetImageExtWildcard()Iterates all registered wxImageHandler objects, and returns a string containing file extension masks suitable for passing to file open/save dialog boxes.
|
HSVtoRGB(hsv)Converts a color in HSV color space to RGB color space.
|
RGBtoHSV(rgb)Converts a color in RGB color space to HSV color space.
|
Property Details |
---|
AlphaBufferSee
|
AlphaDataSee
|
Data |
DataBufferSee
|
HeightSee
|
MaskBlueSee
|
MaskGreenSee
|
MaskRedSee
|
thisownThe membership flag |
WidthSee
|
Home | Trees | Index | Help |
|
---|
Generated by Epydoc 2.1.20050511.rpd on Thu Mar 22 12:07:38 2007 | http://epydoc.sf.net |