wxImage Class Reference
[Graphics Device Interface (GDI)]

#include <wx/image.h>

Inheritance diagram for wxImage:

wxObject

List of all members.


Detailed Description

This class encapsulates a platform-independent image.

An image can be created from data, or using wxBitmap::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 wxImage cannot (currently) be drawn directly to a wxDC. Instead, a platform-specific wxBitmap object must be created from it using the wxBitmap::wxBitmap(wxImage,int depth) constructor. This bitmap can then be drawn in a device context, using wxDC::DrawBitmap.

One colour value of the image may be used as a mask colour which will lead to the automatic creation of a wxMask object associated to the bitmap object.

Alpha channel support

Starting from wxWidgets 2.5.0 wxImage 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 wxIMAGE_ALPHA_TRANSPARENT and wxIMAGE_ALPHA_OPAQUE can be used to indicate those values in a more readable form.

Unlike RGB data, not all images have an alpha channel and before using wxImage::GetAlpha you should check if this image contains an alpha channel with wxImage::HasAlpha. Note that currently only the PNG format has full alpha channel support so only the images loaded from PNG files can have alpha and, if you initialize the image alpha channel yourself using wxImage::SetAlpha, you should save it in PNG format to avoid losing it.

Available image handlers

The following image handlers are available. wxBMPHandler is always installed by default. To use other image formats, install the appropriate handler with wxImage::AddHandler or call wxInitAllImageHandlers().

When saving in PCX format, wxPCXHandler 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, wxPNMHandler will always save as raw RGB.

Library:  wxCore

Category:  Graphics Device Interface (GDI)

Predefined objects/pointers: wxNullImage

See also:
wxBitmap, wxInitAllImageHandlers(), wxPixelData

Public Member Functions

 wxImage ()
 wxImage (int width, int height, bool clear=true)
 wxImage (int width, int height, unsigned char *data, bool static_data=false)
 wxImage (int width, int height, unsigned char *data, unsigned char *alpha, bool static_data=false)
 wxImage (const char *const *xpmData)
 wxImage (const wxString &name, wxBitmapType type=wxBITMAP_TYPE_ANY, int index=-1)
 wxImage (const wxString &name, const wxString &mimetype, int index=-1)
 wxImage (wxInputStream &stream, wxBitmapType type=wxBITMAP_TYPE_ANY, int index=-1)
 wxImage (wxInputStream &stream, const wxString &mimetype, int index=-1)
virtual ~wxImage ()
wxImage Blur (int blurRadius) const
wxImage BlurHorizontal (int blurRadius) const
wxImage BlurVertical (int blurRadius) const
unsigned long ComputeHistogram (wxImageHistogram &histogram) const
bool ConvertAlphaToMask (unsigned char threshold=wxIMAGE_ALPHA_THRESHOLD)
wxBitmap ConvertToBitmap () const
wxImage ConvertToGreyscale (double lr=0.299, double lg=0.587, double lb=1.114) const
wxImage ConvertToMono (unsigned char r, unsigned char g, unsigned char b) const
wxImage Copy () const
bool Create (int width, int height, bool clear=true)
void Destroy ()
bool FindFirstUnusedColour (unsigned char *r, unsigned char *g, unsigned char *b, unsigned char startR=1, unsigned char startG=0, unsigned char startB=0) const
unsigned char GetAlpha (int x, int y) const
unsigned char * GetAlpha () const
unsigned char GetBlue (int x, int y) const
unsigned char * GetData () const
unsigned char GetGreen (int x, int y) const
int GetHeight () const
unsigned char GetMaskBlue () const
unsigned char GetMaskGreen () const
unsigned char GetMaskRed () const
wxString GetOption (const wxString &name) const
int GetOptionInt (const wxString &name) const
bool GetOrFindMaskColour (unsigned char *r, unsigned char *g, unsigned char *b) const
const wxPaletteGetPalette () const
unsigned char GetRed (int x, int y) const
wxImage GetSubImage (const wxRect &rect) const
wxSize GetSize () const
wxBitmapType GetType () const
int GetWidth () const
bool HasAlpha () const
bool HasMask () const
bool HasOption (const wxString &name) const
void InitAlpha ()
bool IsOk () const
bool IsTransparent (int x, int y, unsigned char threshold=wxIMAGE_ALPHA_THRESHOLD) const
virtual bool LoadFile (wxInputStream &stream, wxBitmapType type=wxBITMAP_TYPE_ANY, int index=-1)
virtual bool LoadFile (const wxString &name, wxBitmapType type=wxBITMAP_TYPE_ANY, int index=-1)
virtual bool LoadFile (const wxString &name, const wxString &mimetype, int index=-1)
virtual bool LoadFile (wxInputStream &stream, const wxString &mimetype, int index=-1)
wxImage Mirror (bool horizontally=true) const
void Paste (const wxImage &image, int x, int y)
void Replace (unsigned char r1, unsigned char g1, unsigned char b1, unsigned char r2, unsigned char g2, unsigned char b2)
wxImageRescale (int width, int height, int quality=wxIMAGE_QUALITY_NORMAL)
wxImageResize (const wxSize &size, const wxPoint &pos, int red=-1, int green=-1, int blue=-1)
wxImage Rotate (double angle, const wxPoint &rotationCentre, bool interpolating=true, wxPoint *offsetAfterRotation=NULL) const
wxImage Rotate90 (bool clockwise=true) const
void RotateHue (double angle)
virtual bool SaveFile (wxOutputStream &stream, const wxString &mimetype) const
virtual bool SaveFile (const wxString &name, wxBitmapType type) const
virtual bool SaveFile (const wxString &name, const wxString &mimetype) const
virtual bool SaveFile (const wxString &name) const
virtual bool SaveFile (wxOutputStream &stream, wxBitmapType type) const
wxImage Scale (int width, int height, int quality=wxIMAGE_QUALITY_NORMAL) const
void SetAlpha (unsigned char *alpha=NULL, bool static_data=false)
void SetAlpha (int x, int y, unsigned char alpha)
void SetMask (bool hasMask=true)
void SetMaskColour (unsigned char red, unsigned char green, unsigned char blue)
bool SetMaskFromImage (const wxImage &mask, unsigned char mr, unsigned char mg, unsigned char mb)
void SetPalette (const wxPalette &palette)
void SetRGB (const wxRect &rect, unsigned char red, unsigned char green, unsigned char blue)
void SetType (wxBitmapType type)
wxImage Size (const wxSize &size, const wxPoint &pos, int red=-1, int green=-1, int blue=-1) const
wxImageoperator= (const wxImage &image)
void SetData (unsigned char *data, bool static_data=false)
void SetData (unsigned char *data, int new_width, int new_height, bool static_data=false)
void SetOption (const wxString &name, const wxString &value)
void SetOption (const wxString &name, int value)

Static Public Member Functions

static void AddHandler (wxImageHandler *handler)
static bool CanRead (const wxString &filename)
static void CleanUpHandlers ()
static wxImageHandlerFindHandler (const wxString &name)
static wxImageHandlerFindHandler (const wxString &extension, wxBitmapType imageType)
static wxImageHandlerFindHandler (wxBitmapType imageType)
static wxImageHandlerFindHandlerMime (const wxString &mimetype)
static wxList GetHandlers ()
static wxString GetImageExtWildcard ()
static wxImage::RGBValue HSVtoRGB (const wxImage::HSVValue &hsv)
static void InitStandardHandlers ()
static void InsertHandler (wxImageHandler *handler)
static wxImage::HSVValue RGBtoHSV (const wxImage::RGBValue &rgb)
static bool RemoveHandler (const wxString &name)
static int GetImageCount (const wxString &filename, wxBitmapType type=wxBITMAP_TYPE_ANY)
static int GetImageCount (wxInputStream &stream, wxBitmapType type=wxBITMAP_TYPE_ANY)

Classes

class  HSVValue
class  RGBValue

Constructor & Destructor Documentation

wxImage::wxImage (  ) 

Creates an empty wxImage object without an alpha channel.

wxImage::wxImage ( int  width,
int  height,
bool  clear = true 
)

Creates an image with the given size and clears it if requested.

Does not create an alpha channel.

Parameters:
width Specifies the width of the image.
height Specifies the height of the image.
clear If true, initialize the image to black.

wxImage::wxImage ( int  width,
int  height,
unsigned char *  data,
bool  static_data = false 
)

Creates an image from data in memory. If static_data is false then the wxImage will take ownership of the data and free it afterwards. For this, it has to be allocated with malloc.

Parameters:
width Specifies the width of the image.
height Specifies the height of the image.
data A pointer to RGB data
static_data Indicates if the data should be free'd after use

wxImage::wxImage ( int  width,
int  height,
unsigned char *  data,
unsigned char *  alpha,
bool  static_data = false 
)

Creates an image from data in memory. If static_data is false then the wxImage will take ownership of the data and free it afterwards. For this, it has to be allocated with malloc.

Parameters:
width Specifies the width of the image.
height Specifies the height of the image.
data A pointer to RGB data
alpha A pointer to alpha-channel data
static_data Indicates if the data should be free'd after use

wxImage::wxImage ( const char *const *  xpmData  ) 

Creates an image from XPM data.

Parameters:
xpmData A pointer to XPM image data.

wxImage::wxImage ( const wxString name,
wxBitmapType  type = wxBITMAP_TYPE_ANY,
int  index = -1 
)

Creates an image from a file.

Parameters:
name Name of the file from which to load the image.
type May be one of the following:
  • wxBITMAP_TYPE_BMP: Load a Windows bitmap file.
  • wxBITMAP_TYPE_GIF: Load a GIF bitmap file.
  • wxBITMAP_TYPE_JPEG: Load a JPEG bitmap file.
  • wxBITMAP_TYPE_PNG: Load a PNG bitmap file.
  • wxBITMAP_TYPE_PCX: Load a PCX bitmap file.
  • wxBITMAP_TYPE_PNM: Load a PNM bitmap file.
  • wxBITMAP_TYPE_TIF: Load a TIFF bitmap file.
  • wxBITMAP_TYPE_TGA: Load a TGA bitmap file.
  • wxBITMAP_TYPE_XPM: Load a XPM bitmap file.
  • wxBITMAP_TYPE_ICO: Load a Windows icon file (ICO).
  • wxBITMAP_TYPE_CUR: Load a Windows cursor file (CUR).
  • wxBITMAP_TYPE_ANI: Load a Windows animated cursor file (ANI).
  • wxBITMAP_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 "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.
Remarks:
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 wxImage::AddHandler or wxInitAllImageHandlers.
Note:
You can use GetOptionInt() to get the hotspot when loading cursor files:
            int hotspot_x = image.GetOptionInt(wxIMAGE_OPTION_CUR_HOTSPOT_X);
            int hotspot_y = image.GetOptionInt(wxIMAGE_OPTION_CUR_HOTSPOT_Y);
See also:
LoadFile()

wxImage::wxImage ( const wxString name,
const wxString mimetype,
int  index = -1 
)

Creates an image from a file using MIME-types to specify the type.

Parameters:
name Name of the file from which to load the image.
mimetype MIME type string (for example 'image/jpeg')
index See description in wxImage(const wxString&, wxBitmapType, int) overload.

wxImage::wxImage ( wxInputStream stream,
wxBitmapType  type = wxBITMAP_TYPE_ANY,
int  index = -1 
)

Creates an image from a stream.

Parameters:
stream Opened input stream from which to load the image. Currently, the stream must support seeking.
type See description in wxImage(const wxString&, wxBitmapType, int) overload.
index See description in wxImage(const wxString&, wxBitmapType, int) overload.

wxImage::wxImage ( wxInputStream stream,
const wxString mimetype,
int  index = -1 
)

Creates an image from a stream using MIME-types to specify the type.

Parameters:
stream Opened input stream from which to load the image. Currently, the stream must support seeking.
mimetype MIME type string (for example 'image/jpeg')
index See description in wxImage(const wxString&, wxBitmapType, int) overload.

virtual wxImage::~wxImage (  )  [virtual]

Destructor.

See reference-counted object destruction for more info.


Member Function Documentation

static void wxImage::AddHandler ( wxImageHandler handler  )  [static]

Register an image handler.

wxImage wxImage::Blur ( int  blurRadius  )  const

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.

See also:
BlurHorizontal(), BlurVertical()

wxImage wxImage::BlurHorizontal ( int  blurRadius  )  const

Blurs the image in the horizontal direction only. This should not be used when using a single mask colour for transparency.

See also:
Blur(), BlurVertical()

wxImage wxImage::BlurVertical ( int  blurRadius  )  const

Blurs the image in the vertical direction only. This should not be used when using a single mask colour for transparency.

See also:
Blur(), BlurHorizontal()

static bool wxImage::CanRead ( const wxString filename  )  [static]

Returns true if the current image handlers can read this file

static void wxImage::CleanUpHandlers (  )  [static]

Deletes all image handlers. This function is called by wxWidgets on exit.

unsigned long wxImage::ComputeHistogram ( wxImageHistogram &  histogram  )  const

Computes the histogram of the image. histogram is a reference to wxImageHistogram object. wxImageHistogram is a specialization of wxHashMap "template" and is defined as follows:

        class WXDLLEXPORT wxImageHistogramEntry
        {
        public:
            wxImageHistogramEntry() : index(0), value(0) {}
            unsigned long index;
            unsigned long value;
        };

        WX_DECLARE_EXPORTED_HASH_MAP(unsigned long, wxImageHistogramEntry,
                                    wxIntegerHash, wxIntegerEqual,
                                    wxImageHistogram);

Returns:
Returns number of colours in the histogram.

bool wxImage::ConvertAlphaToMask ( unsigned char  threshold = wxIMAGE_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 mask colour and the alpha channel is removed. Mask colour is chosen automatically using FindFirstUnusedColour().

If the image image doesn't have alpha channel, ConvertAlphaToMask() does nothing.

Returns:
false if FindFirstUnusedColour returns false, true otherwise.

wxBitmap wxImage::ConvertToBitmap (  )  const

Deprecated:
Use the equivalent wxBitmap constructor (which takes wxImage and depth as its arguments) instead.

wxImage wxImage::ConvertToGreyscale ( double  lr = 0.299,
double  lg = 0.587,
double  lb = 1.114 
) const

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 * lr) + (G * lg) + (B * lb).

wxImage wxImage::ConvertToMono ( unsigned char  r,
unsigned char  g,
unsigned char  b 
) const

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.

wxImage wxImage::Copy (  )  const

Returns an identical copy of the image.

bool wxImage::Create ( 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.

Parameters:
width The width of the image in pixels.
height The height of the image in pixels.
clear If true, initialize the image data with zeros.
Returns:
true if the call succeeded, false otherwise.

void wxImage::Destroy (  ) 

Destroys the image data.

bool wxImage::FindFirstUnusedColour ( unsigned char *  r,
unsigned char *  g,
unsigned char *  b,
unsigned char  startR = 1,
unsigned char  startG = 0,
unsigned char  startB = 0 
) const

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.

Returns:
Returns false if there is no unused colour left, true on success.
Note:
This method involves computing the histogram, which is a computationally intensive operation.

static wxImageHandler* wxImage::FindHandler ( const wxString name  )  [static]

Finds the handler with the given name.

Parameters:
name The handler name.
Returns:
A pointer to the handler if found, NULL otherwise.
See also:
wxImageHandler

static wxImageHandler* wxImage::FindHandler ( const wxString extension,
wxBitmapType  imageType 
) [static]

Finds the handler associated with the given extension and type.

Parameters:
extension The file extension, such as "bmp".
imageType The image type; one of the wxBitmapType values.
Returns:
A pointer to the handler if found, NULL otherwise.
See also:
wxImageHandler

static wxImageHandler* wxImage::FindHandler ( wxBitmapType  imageType  )  [static]

Finds the handler associated with the given image type.

Parameters:
imageType The image type; one of the wxBitmapType values.
Returns:
A pointer to the handler if found, NULL otherwise.
See also:
wxImageHandler

static wxImageHandler* wxImage::FindHandlerMime ( const wxString mimetype  )  [static]

Finds the handler associated with the given MIME type.

Parameters:
mimetype MIME type.
Returns:
A pointer to the handler if found, NULL otherwise.
See also:
wxImageHandler

unsigned char wxImage::GetAlpha ( int  x,
int  y 
) const

Return alpha value at given pixel location.

unsigned char* wxImage::GetAlpha (  )  const

Returns pointer to the array storing the alpha values for this image.

This pointer is NULL for the images without the alpha channel. If the image does have it, this pointer may be used to directly manipulate the alpha values which are stored as the RGB ones.

unsigned char wxImage::GetBlue ( int  x,
int  y 
) const

Returns the blue intensity at the given coordinate.

unsigned char* wxImage::GetData (  )  const

Returns the image data as an array.

This is most often used when doing direct image manipulation. The return value points to an array of characters in RGBRGBRGB... format in the top-to-bottom, left-to-right order, that is the first RGB triplet corresponds to the pixel first pixel of the first row, the second one --- to the second pixel of the first row and so on until the end of the first row, with second row following after it and so on.

You should not delete the returned pointer nor pass it to SetData().

unsigned char wxImage::GetGreen ( int  x,
int  y 
) const

Returns the green intensity at the given coordinate.

static wxList wxImage::GetHandlers (  )  [static]

Returns the static list of image format handlers.

See also:
wxImageHandler

int wxImage::GetHeight (  )  const

Gets the height of the image in pixels.

See also:
GetWidth(), GetSize()

static int wxImage::GetImageCount ( const wxString filename,
wxBitmapType  type = wxBITMAP_TYPE_ANY 
) [static]

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 ppened input stream with image data. Currently, the stream must support seeking.

The parameter type may be one of the following values:

  • wxBITMAP_TYPE_BMP: Load a Windows bitmap file.
  • wxBITMAP_TYPE_GIF: Load a GIF bitmap file.
  • wxBITMAP_TYPE_JPEG: Load a JPEG bitmap file.
  • wxBITMAP_TYPE_PNG: Load a PNG bitmap file.
  • wxBITMAP_TYPE_PCX: Load a PCX bitmap file.
  • wxBITMAP_TYPE_PNM: Load a PNM bitmap file.
  • wxBITMAP_TYPE_TIF: Load a TIFF bitmap file.
  • wxBITMAP_TYPE_TGA: Load a TGA bitmap file.
  • wxBITMAP_TYPE_XPM: Load a XPM bitmap file.
  • wxBITMAP_TYPE_ICO: Load a Windows icon file (ICO).
  • wxBITMAP_TYPE_CUR: Load a Windows cursor file (CUR).
  • wxBITMAP_TYPE_ANI: Load a Windows animated cursor file (ANI).
  • wxBITMAP_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).

static int wxImage::GetImageCount ( wxInputStream stream,
wxBitmapType  type = wxBITMAP_TYPE_ANY 
) [static]

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 ppened input stream with image data. Currently, the stream must support seeking.

The parameter type may be one of the following values:

  • wxBITMAP_TYPE_BMP: Load a Windows bitmap file.
  • wxBITMAP_TYPE_GIF: Load a GIF bitmap file.
  • wxBITMAP_TYPE_JPEG: Load a JPEG bitmap file.
  • wxBITMAP_TYPE_PNG: Load a PNG bitmap file.
  • wxBITMAP_TYPE_PCX: Load a PCX bitmap file.
  • wxBITMAP_TYPE_PNM: Load a PNM bitmap file.
  • wxBITMAP_TYPE_TIF: Load a TIFF bitmap file.
  • wxBITMAP_TYPE_TGA: Load a TGA bitmap file.
  • wxBITMAP_TYPE_XPM: Load a XPM bitmap file.
  • wxBITMAP_TYPE_ICO: Load a Windows icon file (ICO).
  • wxBITMAP_TYPE_CUR: Load a Windows cursor file (CUR).
  • wxBITMAP_TYPE_ANI: Load a Windows animated cursor file (ANI).
  • wxBITMAP_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).

static wxString wxImage::GetImageExtWildcard (  )  [static]

Iterates all registered wxImageHandler objects, and returns a string containing file extension masks suitable for passing to file open/save dialog boxes.

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:
                wxFileDialog FileDlg( this, "Choose Image", ::wxGetCwd(), "",
                                      _("Image Files ") + wxImage::GetImageExtWildcard(),
                                      wxFD_OPEN );
See also:
wxImageHandler

unsigned char wxImage::GetMaskBlue (  )  const

Gets the blue value of the mask colour.

unsigned char wxImage::GetMaskGreen (  )  const

Gets the green value of the mask colour.

unsigned char wxImage::GetMaskRed (  )  const

Gets the red value of the mask colour.

wxString wxImage::GetOption ( const wxString name  )  const

Gets a user-defined string-valued option.

Currently the only defined string option is

  • wxIMAGE_OPTION_FILENAME: The name of the file from which the image was loaded.
See also:
SetOption(), GetOptionInt(), HasOption()
Parameters:
name The name of the option, case-insensitive.
Returns:
The value of the option or an empty string if not found. Use HasOption() if an empty string can be a valid option value.

int wxImage::GetOptionInt ( const wxString name  )  const

Gets a user-defined integer-valued option.

The function is case-insensitive to name. If the given option is not present, the function returns 0. Use HasOption() is 0 is a possibly valid value for the option.

Generic options:

  • wxIMAGE_OPTION_MAX_WIDTH and wxIMAGE_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 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 LoadFile() to have any effect.
  • wxIMAGE_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.
  • wxIMAGE_OPTION_RESOLUTIONUNIT: The value of this option determines whether the resolution of the image is specified in centimetres or inches, see wxImageResolution enum elements.
  • wxIMAGE_OPTION_RESOLUTION, wxIMAGE_OPTION_RESOLUTIONX and wxIMAGE_OPTION_RESOLUTIONY: These options define the resolution of the image in the units corresponding to wxIMAGE_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 wxPNGHandler:
  • wxIMAGE_OPTION_PNG_FORMAT: Format for saving a PNG file, see wxImagePNGType for the supported values.
  • wxIMAGE_OPTION_PNG_BITDEPTH: Bit depth for every channel (R/G/B/A).
See also:
SetOption(), GetOption()
Parameters:
name The name of the option, case-insensitive.
Returns:
The value of the option or 0 if not found. Use HasOption() if 0 can be a valid option value.

bool wxImage::GetOrFindMaskColour ( unsigned char *  r,
unsigned char *  g,
unsigned char *  b 
) const

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.

const wxPalette& wxImage::GetPalette (  )  const

Returns the palette associated with the image. Currently the palette is only used when converting to wxBitmap under Windows.

Some of the wxImage 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).

unsigned char wxImage::GetRed ( int  x,
int  y 
) const

Returns the red intensity at the given coordinate.

wxImage wxImage::GetSubImage ( const wxRect rect  )  const

Returns a sub image of the current one as long as the rect belongs entirely to the image.

wxSize wxImage::GetSize (  )  const

Returns the size of the image in pixels.

Since:
2.9.0
See also:
GetHeight(), GetWidth()

wxBitmapType wxImage::GetType (  )  const

Gets the type of image found by LoadFile() or specified with SaveFile().

Since:
2.9.0

int wxImage::GetWidth (  )  const

Gets the width of the image in pixels.

See also:
GetHeight(), GetSize()

static wxImage::RGBValue wxImage::HSVtoRGB ( const wxImage::HSVValue hsv  )  [static]

Converts a color in HSV color space to RGB color space.

bool wxImage::HasAlpha (  )  const

Returns true if this image has alpha channel, false otherwise.

See also:
GetAlpha(), SetAlpha()

bool wxImage::HasMask (  )  const

Returns true if there is a mask active, false otherwise.

bool wxImage::HasOption ( const wxString name  )  const

Returns true if the given option is present. The function is case-insensitive to name.

See also:
SetOption(), GetOption(), GetOptionInt()

void wxImage::InitAlpha (  ) 

Initializes the image alpha channel data.

It is an error to call it if the image already has alpha data. If it doesn't, alpha data will be by default initialized to all pixels being fully opaque. But if the image has a mask colour, all mask pixels will be completely transparent.

static void wxImage::InitStandardHandlers (  )  [static]

Internal use only. Adds standard image format handlers. It only install wxBMPHandler for the time being, which is used by wxBitmap.

This function is called by wxWidgets on startup, and shouldn't be called by the user.

See also:
wxImageHandler, wxInitAllImageHandlers(), wxQuantize

static void wxImage::InsertHandler ( wxImageHandler handler  )  [static]

Adds a handler at the start of the static list of format handlers.

Parameters:
handler A new image format handler object. There is usually only one instance of a given handler class in an application session.
See also:
wxImageHandler

bool wxImage::IsOk (  )  const

Returns true if image data is present.

bool wxImage::IsTransparent ( int  x,
int  y,
unsigned char  threshold = wxIMAGE_ALPHA_THRESHOLD 
) const

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.

virtual bool wxImage::LoadFile ( wxInputStream stream,
wxBitmapType  type = wxBITMAP_TYPE_ANY,
int  index = -1 
) [virtual]

Loads an image from an input stream.

Parameters:
stream Opened input stream from which to load the image. Currently, the stream must support seeking.
type May be one of the following:
  • wxBITMAP_TYPE_BMP: Load a Windows bitmap file.
  • wxBITMAP_TYPE_GIF: Load a GIF bitmap file.
  • wxBITMAP_TYPE_JPEG: Load a JPEG bitmap file.
  • wxBITMAP_TYPE_PNG: Load a PNG bitmap file.
  • wxBITMAP_TYPE_PCX: Load a PCX bitmap file.
  • wxBITMAP_TYPE_PNM: Load a PNM bitmap file.
  • wxBITMAP_TYPE_TIF: Load a TIFF bitmap file.
  • wxBITMAP_TYPE_TGA: Load a TGA bitmap file.
  • wxBITMAP_TYPE_XPM: Load a XPM bitmap file.
  • wxBITMAP_TYPE_ICO: Load a Windows icon file (ICO).
  • wxBITMAP_TYPE_CUR: Load a Windows cursor file (CUR).
  • wxBITMAP_TYPE_ANI: Load a Windows animated cursor file (ANI).
  • wxBITMAP_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 "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.
Returns:
true if the operation succeeded, false otherwise. If the optional index parameter is out of range, false is returned and a call to wxLogError() takes place.
Remarks:
Depending on how wxWidgets has been configured, not all formats may be available.
Note:
You can use GetOptionInt() to get the hotspot when loading cursor files:
            int hotspot_x = image.GetOptionInt(wxIMAGE_OPTION_CUR_HOTSPOT_X);
            int hotspot_y = image.GetOptionInt(wxIMAGE_OPTION_CUR_HOTSPOT_Y);
See also:
SaveFile()

virtual bool wxImage::LoadFile ( const wxString name,
wxBitmapType  type = wxBITMAP_TYPE_ANY,
int  index = -1 
) [virtual]

Loads an image from a file. If no handler type is provided, the library will try to autodetect the format.

Parameters:
name Name of the file from which to load the image.
type See the description in the LoadFile(wxInputStream&, wxBitmapType, int) overload.
index See the description in the LoadFile(wxInputStream&, wxBitmapType, int) overload.

virtual bool wxImage::LoadFile ( const wxString name,
const wxString mimetype,
int  index = -1 
) [virtual]

Loads an image from a file. If no handler type is provided, the library will try to autodetect the format.

Parameters:
name Name of the file from which to load the image.
mimetype MIME type string (for example 'image/jpeg')
index See the description in the LoadFile(wxInputStream&, wxBitmapType, int) overload.

virtual bool wxImage::LoadFile ( wxInputStream stream,
const wxString mimetype,
int  index = -1 
) [virtual]

Loads an image from an input stream.

Parameters:
stream Opened input stream from which to load the image. Currently, the stream must support seeking.
mimetype MIME type string (for example 'image/jpeg')
index See the description in the LoadFile(wxInputStream&, wxBitmapType, int) overload.

wxImage wxImage::Mirror ( bool  horizontally = true  )  const

Returns a mirrored copy of the image. The parameter horizontally indicates the orientation.

void wxImage::Paste ( const wxImage image,
int  x,
int  y 
)

Copy the data of the given image to the specified position in this image.

static wxImage::HSVValue wxImage::RGBtoHSV ( const wxImage::RGBValue rgb  )  [static]

Converts a color in RGB color space to HSV color space.

static bool wxImage::RemoveHandler ( const wxString name  )  [static]

Finds the handler with the given name, and removes it. The handler is not deleted.

Parameters: