Version: 3.0.3

#include <wx/image.h>

+ Inheritance diagram for wxImage:

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.

More on the difference between wxImage and wxBitmap: wxImage 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, wxBitmap 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 wxMemoryDC. By splitting the responsibilities between wxImage/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 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.

While all images have RGB data, not all images have an alpha channel. Before using wxImage::GetAlpha you should check if this image contains an alpha channel with wxImage::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 wxImage::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.

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().

  • wxBMPHandler: For loading (including alpha support) and saving, always installed.
  • wxPNGHandler: For loading and saving. Includes alpha support.
  • wxJPEGHandler: For loading and saving.
  • wxGIFHandler: For loading and saving (see below).
  • wxPCXHandler: For loading and saving (see below).
  • wxPNMHandler: For loading and saving (see below).
  • wxTIFFHandler: For loading and saving. Includes alpha support.
  • wxTGAHandler: For loading and saving. Includes alpha support.
  • wxIFFHandler: For loading only.
  • wxXPMHandler: For loading and saving.
  • wxICOHandler: For loading and saving.
  • wxCURHandler: For loading and saving.
  • wxANIHandler: For loading only.

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.

Saving GIFs requires images of maximum 8 bpp (see wxQuantize), and the alpha channel converted to a mask (see wxImage::ConvertAlphaToMask). Saving an animated GIF requires images of the same size (see wxGIFHandler::SaveAnimation)

Library:  wxCore
Category:  Graphics Device Interface (GDI)

Predefined objects/pointers: wxNullImage

See also
wxBitmap, wxInitAllImageHandlers(), wxPixelData

Classes

class  HSVValue
 A simple class which stores hue, saturation and value as doubles in the range 0.0-1.0. More...
 
class  RGBValue
 A simple class which stores red, green and blue values as 8 bit unsigned integers in the range of 0-255. More...
 

Public Member Functions

 wxImage ()
 Creates an empty wxImage object without an alpha channel. More...
 
 wxImage (int width, int height, bool clear=true)
 Creates an image with the given size and clears it if requested. More...
 
 wxImage (const wxSize &sz, bool clear=true)
 This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts. More...
 
 wxImage (int width, int height, unsigned char *data, bool static_data=false)
 Creates an image from data in memory. More...
 
 wxImage (const wxSize &sz, unsigned char *data, bool static_data=false)
 This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts. More...
 
 wxImage (int width, int height, unsigned char *data, unsigned char *alpha, bool static_data=false)
 Creates an image from data in memory. More...
 
 wxImage (const wxSize &sz, unsigned char *data, unsigned char *alpha, bool static_data=false)
 This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts. More...
 
 wxImage (const char *const *xpmData)
 Creates an image from XPM data. More...
 
 wxImage (const wxString &name, wxBitmapType type=wxBITMAP_TYPE_ANY, int index=-1)
 Creates an image from a file. More...
 
 wxImage (const wxString &name, const wxString &mimetype, int index=-1)
 Creates an image from a file using MIME-types to specify the type. More...
 
 wxImage (wxInputStream &stream, wxBitmapType type=wxBITMAP_TYPE_ANY, int index=-1)
 Creates an image from a stream. More...
 
 wxImage (wxInputStream &stream, const wxString &mimetype, int index=-1)
 Creates an image from a stream using MIME-types to specify the type. More...
 
virtual ~wxImage ()
 Destructor. More...
 
Image creation, initialization and deletion functions
wxImage Copy () const
 Returns an identical copy of this image. More...
 
bool Create (int width, int height, bool clear=true)
 Creates a fresh image. More...
 
bool Create (const wxSize &sz, bool clear=true)
 This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts. More...
 
bool Create (int width, int height, unsigned char *data, bool static_data=false)
 Creates a fresh image. More...
 
bool Create (const wxSize &sz, unsigned char *data, bool static_data=false)
 This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts. More...
 
bool Create (int width, int height, unsigned char *data, unsigned char *alpha, bool static_data=false)
 Creates a fresh image. More...
 
bool Create (const wxSize &sz, unsigned char *data, unsigned char *alpha, bool static_data=false)
 This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts. More...
 
void Clear (unsigned char value=0)
 Initialize the image data with zeroes (the default) or with the byte value given as value. More...
 
void Destroy ()
 Destroys the image data. More...
 
void InitAlpha ()
 Initializes the image alpha channel data. More...
 
Image manipulation functions
wxImage Blur (int blurRadius) const
 Blurs the image in both horizontal and vertical directions by the specified pixel blurRadius. More...
 
wxImage BlurHorizontal (int blurRadius) const
 Blurs the image in the horizontal direction only. More...
 
wxImage BlurVertical (int blurRadius) const
 Blurs the image in the vertical direction only. More...
 
wxImage Mirror (bool horizontally=true) const
 Returns a mirrored copy of the image. More...
 
void Paste (const wxImage &image, int x, int y)
 Copy the data of the given image to the specified position in this image. More...
 
void Replace (unsigned char r1, unsigned char g1, unsigned char b1, unsigned char r2, unsigned char g2, unsigned char b2)
 Replaces the colour specified by r1,g1,b1 by the colour r2,g2,b2. More...
 
wxImageRescale (int width, int height, wxImageResizeQuality quality=wxIMAGE_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. More...
 
wxImageResize (const wxSize &size, const wxPoint &pos, int red=-1, int green=-1, int 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. More...
 
wxImage Rotate (double angle, const wxPoint &rotationCentre, bool interpolating=true, wxPoint *offsetAfterRotation=NULL) const
 Rotates the image about the given point, by angle radians. More...
 
wxImage Rotate90 (bool clockwise=true) const
 Returns a copy of the image rotated 90 degrees in the direction indicated by clockwise. More...
 
wxImage Rotate180 () const
 Returns a copy of the image rotated by 180 degrees. More...
 
void RotateHue (double angle)
 Rotates the hue of each pixel in the image by angle, which is a double in the range of -1.0 to +1.0, where -1.0 corresponds to -360 degrees and +1.0 corresponds to +360 degrees. More...
 
wxImage Scale (int width, int height, wxImageResizeQuality quality=wxIMAGE_QUALITY_NORMAL) const
 Returns a scaled version of the image. More...
 
wxImage Size (const wxSize &size, const wxPoint &pos, int red=-1, int green=-1, int blue=-1) const
 Returns a resized version of this image without scaling it by adding either a border with the given colour or cropping as necessary. More...
 
Conversion functions
bool ConvertAlphaToMask (unsigned char threshold=wxIMAGE_ALPHA_THRESHOLD)
 If the image has alpha channel, this method converts it to mask. More...
 
bool ConvertAlphaToMask (unsigned char mr, unsigned char mg, unsigned char mb, unsigned char threshold=wxIMAGE_ALPHA_THRESHOLD)
 If the image has alpha channel, this method converts it to mask using the specified colour as the mask colour. More...
 
wxImage ConvertToGreyscale (double weight_r, double weight_g, double weight_b) const
 Returns a greyscale version of the image. More...
 
wxImage ConvertToGreyscale () const
 Returns a greyscale version of the image. More...
 
wxImage ConvertToMono (unsigned char r, unsigned char g, unsigned char b) const
 Returns monochromatic version of the image. More...
 
wxImage ConvertToDisabled (unsigned char brightness=255) const
 Returns disabled (dimmed) version of the image. More...
 
Miscellaneous functions
unsigned long ComputeHistogram (wxImageHistogram &histogram) const
 Computes the histogram of the image. More...
 
bool 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. More...
 
wxImageoperator= (const wxImage &image)
 Assignment operator, using reference counting. More...
 
Getters
unsigned char * GetAlpha () const
 Returns pointer to the array storing the alpha values for this image. More...
 
unsigned char * GetData () const
 Returns the image data as an array. More...
 
unsigned char GetAlpha (int x, int y) const
 Return alpha value at given pixel location. More...
 
unsigned char GetRed (int x, int y) const
 Returns the red intensity at the given coordinate. More...
 
unsigned char GetGreen (int x, int y) const
 Returns the green intensity at the given coordinate. More...
 
unsigned char GetBlue (int x, int y) const
 Returns the blue intensity at the given coordinate. More...
 
unsigned char GetMaskRed () const
 Gets the red value of the mask colour. More...
 
unsigned char GetMaskGreen () const
 Gets the green value of the mask colour. More...
 
unsigned char GetMaskBlue () const
 Gets the blue value of the mask colour. More...
 
int GetWidth () const
 Gets the width of the image in pixels. More...
 
int GetHeight () const
 Gets the height of the image in pixels. More...
 
wxSize GetSize () const
 Returns the size of the image in pixels. More...
 
wxString GetOption (const wxString &name) const
 Gets a user-defined string-valued option. More...
 
int GetOptionInt (const wxString &name) const
 Gets a user-defined integer-valued option. More...
 
bool 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. More...
 
const wxPaletteGetPalette () const
 Returns the palette associated with the image. More...
 
wxImage GetSubImage (const wxRect &rect) const
 Returns a sub image of the current one as long as the rect belongs entirely to the image. More...
 
wxBitmapType GetType () const
 Gets the type of image found by LoadFile() or specified with SaveFile(). More...
 
bool HasAlpha () const
 Returns true if this image has alpha channel, false otherwise. More...
 
bool HasMask () const
 Returns true if there is a mask active, false otherwise. More...
 
bool HasOption (const wxString &name) const
 Returns true if the given option is present. More...
 
bool IsOk () const
 Returns true if image data is present. More...
 
bool 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. More...
 
Loading and saving functions
virtual bool LoadFile (wxInputStream &stream, wxBitmapType type=wxBITMAP_TYPE_ANY, int index=-1)
 Loads an image from an input stream. More...
 
virtual bool LoadFile (const wxString &name, wxBitmapType type=wxBITMAP_TYPE_ANY, int index=-1)
 Loads an image from a file. More...
 
virtual bool LoadFile (const wxString &name, const wxString &mimetype, int index=-1)
 Loads an image from a file. More...
 
virtual bool LoadFile (wxInputStream &stream, const wxString &mimetype, int index=-1)
 Loads an image from an input stream. More...
 
virtual bool SaveFile (wxOutputStream &stream, const wxString &mimetype) const
 Saves an image in the given stream. More...
 
virtual bool SaveFile (const wxString &name, wxBitmapType type) const
 Saves an image in the named file. More...
 
virtual bool SaveFile (const wxString &name, const wxString &mimetype) const
 Saves an image in the named file. More...
 
virtual bool SaveFile (const wxString &name) const
 Saves an image in the named file. More...
 
virtual bool SaveFile (wxOutputStream &stream, wxBitmapType type) const
 Saves an image in the given stream. More...
 
Setters
void SetAlpha (unsigned char *alpha=NULL, bool static_data=false)
 This function is similar to SetData() and has similar restrictions. More...
 
void SetAlpha (int x, int y, unsigned char alpha)
 Sets the alpha value for the given pixel. More...
 
void ClearAlpha ()
 Removes the alpha channel from the image. More...
 
void SetData (unsigned char *data, bool static_data=false)
 Sets the image data without performing checks. More...
 
void SetData (unsigned char *data, int new_width, int new_height, bool static_data=false)
 This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts. More...
 
void SetMask (bool hasMask=true)
 Specifies whether there is a mask or not. More...
 
void SetMaskColour (unsigned char red, unsigned char green, unsigned char blue)
 Sets the mask colour for this image (and tells the image to use the mask). More...
 
bool SetMaskFromImage (const wxImage &mask, unsigned char mr, unsigned char mg, unsigned char 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. More...
 
void SetOption (const wxString &name, const wxString &value)
 Sets a user-defined option. More...
 
void SetOption (const wxString &name, int value)
 This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts. More...
 
void SetPalette (const wxPalette &palette)
 Associates a palette with the image. More...
 
void SetRGB (int x, int y, unsigned char r, unsigned char g, unsigned char b)
 Set the color of the pixel at the given x and y coordinate. More...
 
void SetRGB (const wxRect &rect, unsigned char red, unsigned char green, unsigned char blue)
 Sets the colour of the pixels within the given rectangle. More...
 
void SetType (wxBitmapType type)
 Set the type of image returned by GetType(). More...
 
- Public Member Functions inherited from wxObject
 wxObject ()
 Default ctor; initializes to NULL the internal reference data. More...
 
 wxObject (const wxObject &other)
 Copy ctor. More...
 
virtual ~wxObject ()
 Destructor. More...
 
virtual wxClassInfoGetClassInfo () const
 This virtual function is redefined for every class that requires run-time type information, when using the wxDECLARE_CLASS macro (or similar). More...
 
wxObjectRefDataGetRefData () const
 Returns the wxObject::m_refData pointer, i.e. the data referenced by this object. More...
 
bool IsKindOf (const wxClassInfo *info) const
 Determines whether this class is a subclass of (or the same class as) the given class. More...
 
bool IsSameAs (const wxObject &obj) const
 Returns true if this object has the same data pointer as obj. More...
 
void Ref (const wxObject &clone)
 Makes this object refer to the data in clone. More...
 
void SetRefData (wxObjectRefData *data)
 Sets the wxObject::m_refData pointer. More...
 
void UnRef ()
 Decrements the reference count in the associated data, and if it is zero, deletes the data. More...
 
void UnShare ()
 This is the same of AllocExclusive() but this method is public. More...
 
void operator delete (void *buf)
 The delete operator is defined for debugging versions of the library only, when the identifier WXDEBUG is defined. More...
 
void * operator new (size_t size, const wxString &filename=NULL, int lineNum=0)
 The new operator is defined for debugging versions of the library only, when the identifier WXDEBUG is defined. More...
 

Static Public Member Functions

static bool CanRead (const wxString &filename)
 Returns true if at least one of the available image handlers can read the file with the given name. More...
 
static bool CanRead (wxInputStream &stream)
 Returns true if at least one of the available image handlers can read the data in the given stream. More...
 
static wxString GetImageExtWildcard ()
 Iterates all registered wxImageHandler objects, and returns a string containing file extension masks suitable for passing to file open/save dialog boxes. More...
 
static wxImage::HSVValue RGBtoHSV (const wxImage::RGBValue &rgb)
 Converts a color in RGB color space to HSV color space. More...
 
static wxImage::RGBValue HSVtoRGB (const wxImage::HSVValue &hsv)
 Converts a color in HSV color space to RGB color space. More...
 
Handler management functions
static void AddHandler (wxImageHandler *handler)
 Register an image handler. More...
 
static void CleanUpHandlers ()
 Deletes all image handlers. More...
 
static wxImageHandlerFindHandler (const wxString &name)
 Finds the handler with the given name. More...
 
static wxImageHandlerFindHandler (const wxString &extension, wxBitmapType imageType)
 Finds the handler associated with the given extension and type. More...
 
static wxImageHandlerFindHandler (wxBitmapType imageType)
 Finds the handler associated with the given image type. More...
 
static wxImageHandlerFindHandlerMime (const wxString &mimetype)
 Finds the handler associated with the given MIME type. More...
 
static wxList & GetHandlers ()
 Returns the static list of image format handlers. More...
 
static void InitStandardHandlers ()
 Internal use only. More...
 
static void InsertHandler (wxImageHandler *handler)
 Adds a handler at the start of the static list of format handlers. More...
 
static bool RemoveHandler (const wxString &name)
 Finds the handler with the given name, and removes it. More...
 
static int GetImageCount (const wxString &filename, wxBitmapType type=wxBITMAP_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. More...
 
static int GetImageCount (wxInputStream &stream, wxBitmapType type=wxBITMAP_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. More...
 

Additional Inherited Members

- Protected Member Functions inherited from wxObject
void AllocExclusive ()
 Ensure that this object's data is not shared with any other object. More...
 
virtual wxObjectRefDataCreateRefData () const
 Creates a new instance of the wxObjectRefData-derived class specific to this object and returns it. More...
 
virtual wxObjectRefDataCloneRefData (const wxObjectRefData *data) const
 Creates a new instance of the wxObjectRefData-derived class specific to this object and initializes it copying data. More...
 
- Protected Attributes inherited from wxObject
wxObjectRefDatam_refData
 Pointer to an object which is the object's reference-counted data. More...
 

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
widthSpecifies the width of the image.
heightSpecifies the height of the image.
clearIf true, initialize the image to black.
wxImage::wxImage ( const wxSize sz,
bool  clear = true 
)

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

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
widthSpecifies the width of the image.
heightSpecifies the height of the image.
dataA pointer to RGB data
static_dataIndicates if the data should be free'd after use
wxImage::wxImage ( const wxSize sz,
unsigned char *  data,
bool  static_data = false 
)

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

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
widthSpecifies the width of the image.
heightSpecifies the height of the image.
dataA pointer to RGB data
alphaA pointer to alpha-channel data
static_dataIndicates if the data should be free'd after use
wxImage::wxImage ( const wxSize sz,
unsigned char *  data,
unsigned char *  alpha,
bool  static_data = false 
)

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

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

Creates an image from XPM data.

Parameters
xpmDataA pointer to XPM image data.

wxPerl Note: Not supported by wxPerl.

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

Creates an image from a file.

Parameters
nameName of the file from which to load the image.
typeMay 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_TIFF: 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.
indexIndex 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
nameName of the file from which to load the image.
mimetypeMIME type string (for example 'image/jpeg')
indexSee 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
streamOpened input stream from which to load the image. Currently, the stream must support seeking.
typeSee description in wxImage(const wxString&, wxBitmapType, int) overload.
indexSee 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
streamOpened input stream from which to load the image. Currently, the stream must support seeking.
mimetypeMIME type string (for example 'image/jpeg')
indexSee 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.

Typical example of use:

wxImage::AddHandler(new wxPNGHandler);

See Available image handlers for a list of the available handlers. You can also use wxInitAllImageHandlers() to add handlers for all the image formats supported by wxWidgets at once.

Parameters
handlerA heap-allocated handler object which will be deleted by wxImage if it is removed later by RemoveHandler() or at program shutdown.
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 at least one of the available image handlers can read the file with the given name.

See wxImageHandler::CanRead for more info.

static bool wxImage::CanRead ( wxInputStream stream)
static

Returns true if at least one of the available image handlers can read the data in the given stream.

See wxImageHandler::CanRead for more info.

static void wxImage::CleanUpHandlers ( )
static

Deletes all image handlers.

This function is called by wxWidgets on exit.

void wxImage::Clear ( unsigned char  value = 0)

Initialize the image data with zeroes (the default) or with the byte value given as value.

Since
2.9.0
void wxImage::ClearAlpha ( )

Removes the alpha channel from the image.

This function should only be called if the image has alpha channel data, use HasAlpha() to check for this.

Since
2.9.1
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,
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.

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 FindFirstUnusedColour() by this function, see the overload below if you this is not appropriate.

Returns
Returns true on success, false on error.
bool wxImage::ConvertAlphaToMask ( unsigned char  mr,
unsigned char  mg,
unsigned char  mb,
unsigned char  threshold = wxIMAGE_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.

Since
2.9.0
Parameters
mrThe red component of the mask colour.
mgThe green component of the mask colour.
mbThe blue component of the mask colour.
thresholdPixels 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.
Returns
Returns true on success, false on error.
wxImage wxImage::ConvertToDisabled ( unsigned char  brightness = 255) const

Returns disabled (dimmed) version of the image.

Since
2.9.0
wxImage wxImage::ConvertToGreyscale ( double  weight_r,
double  weight_g,
double  weight_b 
) 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 * weight_r) + (G * weight_g) + (B * weight_b).

wxImage wxImage::ConvertToGreyscale ( ) const

Returns a greyscale version of the image.

Since
2.9.0
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 this image.

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

Creates a fresh image.

See wxImage::wxImage(int,int,bool) for more info.

Returns
true if the call succeeded, false otherwise.
bool wxImage::Create ( const wxSize sz,
bool  clear = true 
)

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

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

Creates a fresh image.

See wxImage::wxImage(int,int,unsigned char*,bool) for more info.

Returns
true if the call succeeded, false otherwise.
bool wxImage::Create ( const wxSize sz,
unsigned char *  data,
bool  static_data = false 
)

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

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

Creates a fresh image.

See wxImage::wxImage(int,int,unsigned char*,unsigned char*,bool) for more info.

Returns
true if the call succeeded, false otherwise.
bool wxImage::Create ( const wxSize sz,
unsigned char *  data,
unsigned char *  alpha,
bool  static_data = false 
)

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

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
nameThe 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
extensionThe file extension, such as "bmp".
imageTypeThe 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
imageTypeThe 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
mimetypeMIME type.
Returns
A pointer to the handler if found, NULL otherwise.
See also
wxImageHandler
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::GetAlpha ( int  x,
int  y 
) const

Return alpha value at given pixel location.

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 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 opened input stream with image data.

See wxImageHandler::GetImageCount() for more info.

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_TIFF: 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 as well as animated GIFs for which this function returns the number of frames in the animation).
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 opened input stream with image data.

See wxImageHandler::GetImageCount() for more info.

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_TIFF: 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 as well as animated GIFs for which this function returns the number of frames in the animation).
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(),
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.

Generic options:

  • wxIMAGE_OPTION_FILENAME: The name of the file from which the image was loaded.

Options specific to wxGIFHandler:

  • wxIMAGE_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.
Parameters
nameThe 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.
See also
SetOption(), GetOptionInt(), HasOption()
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() if 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_ORIGINAL_WIDTH and wxIMAGE_OPTION_ORIGINAL_HEIGHT: These options will return the original size of the image if either wxIMAGE_OPTION_MAX_WIDTH or wxIMAGE_OPTION_MAX_HEIGHT is specified.
    Since
    2.9.3
  • 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).
  • wxIMAGE_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).
  • wxIMAGE_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.
  • wxIMAGE_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.
  • wxIMAGE_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.
  • wxIMAGE_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 wxTIFFHandler:

  • wxIMAGE_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 wxIMAGE_OPTION_TIFF_SAMPLESPERPIXEL.
  • wxIMAGE_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 wxIMAGE_OPTION_TIFF_BITSPERSAMPLE. A value of 3 (the default) will result in an RGB image.
  • wxIMAGE_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.
  • wxIMAGE_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 wxIMAGE_OPTION_TIFF_PHOTOMETRIC and set it to either PHOTOMETRIC_MINISWHITE or PHOTOMETRIC_MINISBLACK. The other values are taken care of.
Note
Be careful when combining the options wxIMAGE_OPTION_TIFF_SAMPLESPERPIXEL, wxIMAGE_OPTION_TIFF_BITSPERSAMPLE, and wxIMAGE_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.
Parameters
nameThe 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.
See also
SetOption(), GetOption()
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.

wxSize wxImage::GetSize ( ) const

Returns the size of the image in pixels.

Since
2.9.0
See also
GetHeight(), GetWidth()
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.

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()
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.

The lists of the currently supported options are in GetOption() and GetOptionInt() function docs.

See also
SetOption(), GetOption(), GetOptionInt()
static wxImage::RGBValue wxImage::HSVtoRGB ( const wxImage::HSVValue hsv)
static

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

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
handlerA 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
streamOpened input stream from which to load the image. Currently, the stream must support seeking.
typeMay 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_TIFF: 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.
indexIndex 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
nameName of the file from which to load the image.
typeSee the description in the LoadFile(wxInputStream&, wxBitmapType, int) overload.
indexSee 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
nameName of the file from which to load the image.
mimetypeMIME type string (for example 'image/jpeg')
indexSee 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
streamOpened input stream from which to load the image. Currently, the stream must support seeking.
mimetypeMIME type string (for example 'image/jpeg')
indexSee 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.

wxImage& wxImage::operator= ( const wxImage image)

Assignment operator, using reference counting.

Parameters
imageImage to assign.
Returns
Returns 'this' object.
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 bool wxImage::RemoveHandler ( const wxString name)
static

Finds the handler with the given name, and removes it.

The handler is also deleted.

Parameters
nameThe handler name.
Returns
true if the handler was found and removed, false otherwise.
See also
wxImageHandler
void wxImage::Replace ( unsigned char  r1,
unsigned char  g1,
unsigned char  b1,
unsigned char  r2,
unsigned char  g2,
unsigned char  b2 
)

Replaces the colour specified by r1,g1,b1 by the colour r2,g2,b2.

wxImage& wxImage::Rescale ( int  width,
int  height,
wxImageResizeQuality  quality = wxIMAGE_QUALITY_NORMAL 
)

Changes the size of the image in-place by scaling it: after a call to this function,the image will have the given width and height.

For a description of the quality parameter, see the Scale() function. Returns the (modified) image itself.

See also
Scale()
wxImage& wxImage::Resize ( const wxSize size,
const wxPoint pos,
int  red = -1,
int  green = -1,
int  blue = -1 
)

Changes the size of the image in-place without scaling it by adding either a border with the given colour or cropping as necessary.

The image is pasted into a new image with the given size and background colour at the position pos relative to the upper left of the new image.

If red = green = blue = -1 then use either the current mask colour if set or find, use, and set a suitable mask colour for any newly exposed areas.

Returns
The (modified) image itself.
See also
Size()
static wxImage::HSVValue wxImage::RGBtoHSV ( const wxImage::RGBValue rgb)
static

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

wxImage wxImage::Rotate ( double  angle,
const wxPoint rotationCentre,
bool  interpolating = true,
wxPoint offsetAfterRotation = NULL 
) const

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.

wxImage wxImage::Rotate180 ( ) const

Returns a copy of the image rotated by 180 degrees.

Since
2.9.2
wxImage wxImage::Rotate90 ( bool  clockwise = true) const

Returns a copy of the image rotated 90 degrees in the direction indicated by clockwise.

void wxImage::RotateHue ( double  angle)

Rotates the hue of each pixel in the image by angle, which is a double in the range of -1.0 to +1.0, where -1.0 corresponds to -360 degrees and +1.0 corresponds to +360 degrees.

virtual bool wxImage::SaveFile ( wxOutputStream stream,
const wxString mimetype 
) const
virtual

Saves an image in the given stream.

Parameters
streamOpened output stream to save the image to.
mimetypeMIME type.
Returns
true if the operation succeeded, false otherwise.
Remarks
Depending on how wxWidgets has been configured, not all formats may be available.
Note
You can use SetOption() to set the hotspot when saving an image into a cursor file (default hotspot is in the centre of the image):
image.SetOption(wxIMAGE_OPTION_CUR_HOTSPOT_X, hotspotX);
image.SetOption(wxIMAGE_OPTION_CUR_HOTSPOT_Y, hotspotY);
See also
LoadFile()
virtual bool wxImage::SaveFile ( const wxString name,
wxBitmapType  type 
) const
virtual

Saves an image in the named file.

Parameters
nameName of the file to save the image to.
typeCurrently these types can be used:
  • wxBITMAP_TYPE_BMP: Save a BMP image file.
  • wxBITMAP_TYPE_JPEG: Save a JPEG image file.
  • wxBITMAP_TYPE_PNG: Save a PNG image file.
  • wxBITMAP_TYPE_PCX: Save a PCX image file (tries to save as 8-bit if possible, falls back to 24-bit otherwise).
  • wxBITMAP_TYPE_PNM: Save a PNM image file (as raw RGB always).
  • wxBITMAP_TYPE_TIFF: Save a TIFF image file.
  • wxBITMAP_TYPE_XPM: Save a XPM image file.
  • wxBITMAP_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.
  • wxBITMAP_TYPE_CUR: Save a Windows cursor file (CUR).
virtual bool wxImage::SaveFile ( const wxString name,
const wxString mimetype 
) const
virtual

Saves an image in the named file.

Parameters
nameName of the file to save the image to.
mimetypeMIME type.
virtual bool wxImage::SaveFile ( const wxString name) const
virtual

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.

Parameters
nameName of the file to save the image to.
virtual bool wxImage::SaveFile ( wxOutputStream stream,
wxBitmapType  type 
) const
virtual

Saves an image in the given stream.

Parameters
streamOpened output stream to save the image to.
typeMIME type.
wxImage wxImage::Scale ( int  width,
int  height,
wxImageResizeQuality  quality = wxIMAGE_QUALITY_NORMAL 
) const

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 wxMemoryDC into another wxMemoryDC.

The parameter quality determines what method to use for resampling the image, see wxImageResizeQuality documentation.

It should be noted that although using wxIMAGE_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
wxBitmap bmp = ...;
// rescale it to have size of 32*32
if ( bmp.GetWidth() != 32 || bmp.GetHeight() != 32 )
{
wxImage image = bmp.ConvertToImage();
bmp = wxBitmap(image.Scale(32, 32));
// another possibility:
image.Rescale(32, 32);
bmp = image;
}
See also
Rescale()
void wxImage::SetAlpha ( unsigned char *  alpha = NULL,
bool  static_data = false 
)

This function is similar to SetData() and has similar restrictions.

The pointer passed to it may however be NULL in which case the function will allocate the alpha array internally – this is useful to add alpha channel data to an image which doesn't have any.

If the pointer is not NULL, it must have one byte for each image pixel and be allocated with malloc(). wxImage takes ownership of the pointer and will free it unless static_data parameter is set to true – in this case the caller should do it.

void wxImage::SetAlpha ( int  x,
int  y,
unsigned char  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.

void wxImage::SetData ( unsigned char *  data,
bool  static_data = false 
)

Sets the image data without performing checks.

The data given must have the size (width*height*3) or results will be unexpected. Don't use this method if you aren't sure you know what you are doing.

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 wxImage object, that will be responsible for deleting it. Do not pass to this function a pointer obtained through GetData().

void wxImage::SetData ( unsigned char *  data,
int  new_width,
int  new_height,
bool  static_data = false 
)

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

void wxImage::SetMask ( bool  hasMask = true)

Specifies whether there is a mask or not.

The area of the mask is determined by the current mask colour.

void wxImage::SetMaskColour ( unsigned char  red,
unsigned char  green,
unsigned char  blue 
)

Sets the mask colour for this image (and tells the image to use the mask).

bool wxImage::SetMaskFromImage ( const wxImage mask,
unsigned char  mr,
unsigned char  mg,
unsigned char  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.

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.
void wxImage::SetOption ( const wxString name,
const wxString 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 GetOption() and GetOptionInt() function docs.

See also
GetOption(), GetOptionInt(), HasOption()
void wxImage::SetOption ( const wxString name,
int  value 
)

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

void wxImage::SetPalette ( const wxPalette palette)

Associates a palette with the image.

The palette may be used when converting wxImage to wxBitmap (MSW only at present) or in file save operations (none as yet).

void wxImage::SetRGB ( int  x,
int  y,
unsigned char  r,
unsigned char  g,
unsigned char  b 
)

Set the color of the pixel at the given x and y coordinate.

void wxImage::SetRGB ( const wxRect rect,
unsigned char  red,
unsigned char  green,
unsigned char  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.

void wxImage::SetType ( wxBitmapType  type)

Set the type of image returned by 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 LoadFile() (which would set the type correctly automatically).

Notice that the image must be created before this function is called.

Since
2.9.0
Parameters
typeOne of bitmap type constants, wxBITMAP_TYPE_INVALID is a valid value for it and can be used to reset the bitmap type to default but wxBITMAP_TYPE_MAX is not allowed here.
wxImage wxImage::Size ( const wxSize size,
const wxPoint pos,
int  red = -1,
int  green = -1,
int  blue = -1 
) const

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.

See also
Resize()