1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: interface of wxImageHandler and wxImage
4 // Author: wxWidgets team
5 // Licence: wxWindows licence
6 /////////////////////////////////////////////////////////////////////////////
9 Possible values for the image resolution option.
11 @see wxImage::GetOptionInt().
13 enum wxImageResolution
15 /// Resolution not specified.
16 wxIMAGE_RESOLUTION_NONE
= 0,
18 /// Resolution specified in inches.
19 wxIMAGE_RESOLUTION_INCHES
= 1,
21 /// Resolution specified in centimetres.
22 wxIMAGE_RESOLUTION_CM
= 2
26 Image resize algorithm.
28 This is used with wxImage::Scale() and wxImage::Rescale().
30 enum wxImageResizeQuality
32 /// Simplest and fastest algorithm.
33 wxIMAGE_QUALITY_NEAREST
,
35 /// Compromise between wxIMAGE_QUALITY_NEAREST and wxIMAGE_QUALITY_BICUBIC.
36 wxIMAGE_QUALITY_BILINEAR
,
38 /// Highest quality but slowest execution time.
39 wxIMAGE_QUALITY_BICUBIC
,
42 Use surrounding pixels to calculate an average that will be used for
43 new pixels. This method is typically used when reducing the size of
46 wxIMAGE_QUALITY_BOX_AVERAGE
,
49 Default image resizing algorithm used by wxImage::Scale(). Currently
50 the same as wxIMAGE_QUALITY_NEAREST.
52 wxIMAGE_QUALITY_NORMAL
,
55 Best image resizing algorithm. Since version 2.9.2 this results in
56 wxIMAGE_QUALITY_BOX_AVERAGE being used when reducing the size of the
57 image (meaning that both the new width and height will be smaller than
58 the original size). Otherwise wxIMAGE_QUALITY_BICUBIC is used.
64 Possible values for PNG image type option.
66 @see wxImage::GetOptionInt().
70 wxPNG_TYPE_COLOUR
= 0, ///< Colour PNG image.
71 wxPNG_TYPE_GREY
= 2, ///< Greyscale PNG image converted from RGB.
72 wxPNG_TYPE_GREY_RED
= 3, ///< Greyscale PNG image using red as grey.
73 wxPNG_TYPE_PALETTE
= 4 ///< Palette encoding.
80 #define wxIMAGE_OPTION_QUALITY wxString("quality")
81 #define wxIMAGE_OPTION_FILENAME wxString("FileName")
82 #define wxIMAGE_OPTION_RESOLUTION wxString("Resolution")
83 #define wxIMAGE_OPTION_RESOLUTIONX wxString("ResolutionX")
84 #define wxIMAGE_OPTION_RESOLUTIONY wxString("ResolutionY")
85 #define wxIMAGE_OPTION_RESOLUTIONUNIT wxString("ResolutionUnit")
86 #define wxIMAGE_OPTION_MAX_WIDTH wxString("MaxWidth")
87 #define wxIMAGE_OPTION_MAX_HEIGHT wxString("MaxHeight")
88 #define wxIMAGE_OPTION_ORIGINAL_WIDTH wxString("OriginalWidth")
89 #define wxIMAGE_OPTION_ORIGINAL_HEIGHT wxString("OriginalHeight")
91 #define wxIMAGE_OPTION_BMP_FORMAT wxString("wxBMP_FORMAT")
92 #define wxIMAGE_OPTION_CUR_HOTSPOT_X wxString("HotSpotX")
93 #define wxIMAGE_OPTION_CUR_HOTSPOT_Y wxString("HotSpotY")
95 #define wxIMAGE_OPTION_GIF_COMMENT wxString("GifComment")
97 #define wxIMAGE_OPTION_PNG_FORMAT wxString("PngFormat")
98 #define wxIMAGE_OPTION_PNG_BITDEPTH wxString("PngBitDepth")
99 #define wxIMAGE_OPTION_PNG_FILTER wxString("PngF")
100 #define wxIMAGE_OPTION_PNG_COMPRESSION_LEVEL wxString("PngZL")
101 #define wxIMAGE_OPTION_PNG_COMPRESSION_MEM_LEVEL wxString("PngZM")
102 #define wxIMAGE_OPTION_PNG_COMPRESSION_STRATEGY wxString("PngZS")
103 #define wxIMAGE_OPTION_PNG_COMPRESSION_BUFFER_SIZE wxString("PngZB")
105 #define wxIMAGE_OPTION_TIFF_BITSPERSAMPLE wxString("BitsPerSample")
106 #define wxIMAGE_OPTION_TIFF_SAMPLESPERPIXEL wxString("SamplesPerPixel")
107 #define wxIMAGE_OPTION_TIFF_COMPRESSION wxString("Compression")
108 #define wxIMAGE_OPTION_TIFF_PHOTOMETRIC wxString("Photometric")
109 #define wxIMAGE_OPTION_TIFF_IMAGEDESCRIPTOR wxString("ImageDescriptor")
114 wxBMP_24BPP
= 24, // default, do not need to set
115 //wxBMP_16BPP = 16, // wxQuantize can only do 236 colors?
116 wxBMP_8BPP
= 8, // 8bpp, quantized colors
117 wxBMP_8BPP_GREY
= 9, // 8bpp, rgb averaged to greys
118 wxBMP_8BPP_GRAY
= wxBMP_8BPP_GREY
,
119 wxBMP_8BPP_RED
= 10, // 8bpp, red used as greyscale
120 wxBMP_8BPP_PALETTE
= 11, // 8bpp, use the wxImage's palette
121 wxBMP_4BPP
= 4, // 4bpp, quantized colors
122 wxBMP_1BPP
= 1, // 1bpp, quantized "colors"
123 wxBMP_1BPP_BW
= 2 // 1bpp, black & white from red
128 @class wxImageHandler
130 This is the base class for implementing image file loading/saving, and
131 image creation from data.
132 It is used within wxImage and is not normally seen by the application.
134 If you wish to extend the capabilities of wxImage, derive a class from
135 wxImageHandler and add the handler using wxImage::AddHandler in your
136 application initialization.
138 Note that all wxImageHandlers provided by wxWidgets are part of
139 the @ref page_libs_wxcore library.
140 For details about the default handlers, please see the section
141 @ref image_handlers in the wxImage class documentation.
144 @section imagehandler_note Note (Legal Issue)
146 This software is based in part on the work of the Independent JPEG Group.
147 (Applies when wxWidgets is linked with JPEG support.
148 wxJPEGHandler uses libjpeg created by IJG.)
157 @see wxImage, wxInitAllImageHandlers()
159 class wxImageHandler
: public wxObject
165 In your own default constructor, initialise the members
166 m_name, m_extension and m_type.
171 Destroys the wxImageHandler object.
173 virtual ~wxImageHandler();
176 Returns @true if this handler supports the image format contained in the
179 This function doesn't modify the current stream position (because it
180 restores the original position before returning; this however requires the
181 stream to be seekable; see wxStreamBase::IsSeekable).
183 bool CanRead( wxInputStream
& stream
);
186 Returns @true if this handler supports the image format contained in the
187 file with the given name.
189 This function doesn't modify the current stream position (because it
190 restores the original position before returning; this however requires the
191 stream to be seekable; see wxStreamBase::IsSeekable).
193 bool CanRead( const wxString
& filename
);
196 Gets the preferred file extension associated with this handler.
198 @see GetAltExtensions()
200 const wxString
& GetExtension() const;
203 Returns the other file extensions associated with this handler.
205 The preferred extension for this handler is returned by GetExtension().
209 const wxArrayString
& GetAltExtensions() const;
212 If the image file contains more than one image and the image handler is capable
213 of retrieving these individually, this function will return the number of
217 Opened input stream for reading image data.
218 This function doesn't modify the current stream position (because it
219 restores the original position before returning; this however requires the
220 stream to be seekable; see wxStreamBase::IsSeekable).
222 @return Number of available images. For most image handlers, this is 1
223 (exceptions are TIFF and ICO formats as well as animated GIFs
224 for which this function returns the number of frames in the
227 virtual int GetImageCount(wxInputStream
& stream
);
230 Gets the MIME type associated with this handler.
232 const wxString
& GetMimeType() const;
235 Gets the name of this handler.
237 const wxString
& GetName() const;
240 Gets the image type associated with this handler.
242 wxBitmapType
GetType() const;
245 Loads a image from a stream, putting the resulting data into @a image.
247 If the image file contains more than one image and the image handler is
248 capable of retrieving these individually, @a index indicates which image
249 to read from the stream.
252 The image object which is to be affected by this operation.
254 Opened input stream for reading image data.
256 If set to @true, errors reported by the image handler will produce
259 The index of the image in the file (starting from zero).
261 @return @true if the operation succeeded, @false otherwise.
263 @see wxImage::LoadFile, wxImage::SaveFile, SaveFile()
265 virtual bool LoadFile(wxImage
* image
, wxInputStream
& stream
,
266 bool verbose
= true, int index
= -1);
269 Saves a image in the output stream.
272 The image object which is to be affected by this operation.
274 Opened output stream for writing the data.
276 If set to @true, errors reported by the image handler will produce
279 @return @true if the operation succeeded, @false otherwise.
281 @see wxImage::LoadFile, wxImage::SaveFile, LoadFile()
283 virtual bool SaveFile(wxImage
* image
, wxOutputStream
& stream
,
284 bool verbose
= true);
287 Sets the preferred file extension associated with this handler.
290 File extension without leading dot.
292 @see SetAltExtensions()
294 void SetExtension(const wxString
& extension
);
297 Sets the alternative file extensions associated with this handler.
300 Array of file extensions.
306 void SetAltExtensions(const wxArrayString
& extensions
);
309 Sets the handler MIME type.
314 void SetMimeType(const wxString
& mimetype
);
317 Sets the handler name.
322 void SetName(const wxString
& name
);
325 Retrieve the version information about the image library used by this
328 This method is not present in wxImageHandler class itself but is
329 present in a few of the classes deriving from it, currently
330 wxJPEGHandler, wxPNGHandler and wxTIFFHandler. It returns the
331 information about the version of the image library being used for the
332 corresponding handler implementation.
336 static wxVersionInfo
GetLibraryVersionInfo();
340 Called to get the number of images available in a multi-image file
343 NOTE: this function is allowed to change the current stream position
344 since GetImageCount() will take care of restoring it later
346 virtual int DoGetImageCount( wxInputStream
& stream
);
349 Called to test if this handler can read an image from the given stream.
351 NOTE: this function is allowed to change the current stream position
352 since CallDoCanRead() will take care of restoring it later
354 virtual bool DoCanRead( wxInputStream
& stream
) = 0;
359 Constant used to indicate the alpha value conventionally defined as
360 the complete transparency.
362 const unsigned char wxIMAGE_ALPHA_TRANSPARENT
= 0;
365 Constant used to indicate the alpha value conventionally defined as
366 the complete opacity.
368 const unsigned char wxIMAGE_ALPHA_OPAQUE
= 0xff;
370 const unsigned char wxIMAGE_ALPHA_THRESHOLD
= 0x80;
376 This class encapsulates a platform-independent image.
378 An image can be created from data, or using wxBitmap::ConvertToImage.
379 An image can be loaded from a file in a variety of formats, and is extensible
380 to new formats via image format handlers. Functions are available to set and
381 get image bits, so it can be used for basic image manipulation.
383 A wxImage cannot (currently) be drawn directly to a wxDC.
384 Instead, a platform-specific wxBitmap object must be created from it using
385 the wxBitmap::wxBitmap(wxImage,int depth) constructor.
386 This bitmap can then be drawn in a device context, using wxDC::DrawBitmap.
388 More on the difference between wxImage and wxBitmap: wxImage is just a
389 buffer of RGB bytes with an optional buffer for the alpha bytes. It is all
390 generic, platform independent and image file format independent code. It
391 includes generic code for scaling, resizing, clipping, and other manipulations
392 of the image data. OTOH, wxBitmap is intended to be a wrapper of whatever is
393 the native image format that is quickest/easiest to draw to a DC or to be the
394 target of the drawing operations performed on a wxMemoryDC. By splitting the
395 responsibilities between wxImage/wxBitmap like this then it's easier to use
396 generic code shared by all platforms and image types for generic operations and
397 platform specific code where performance or compatibility is needed.
399 One colour value of the image may be used as a mask colour which will lead to
400 the automatic creation of a wxMask object associated to the bitmap object.
403 @section image_alpha Alpha channel support
405 Starting from wxWidgets 2.5.0 wxImage supports alpha channel data, that is
406 in addition to a byte for the red, green and blue colour components for each
407 pixel it also stores a byte representing the pixel opacity.
409 An alpha value of 0 corresponds to a transparent pixel (null opacity) while
410 a value of 255 means that the pixel is 100% opaque.
411 The constants ::wxIMAGE_ALPHA_TRANSPARENT and ::wxIMAGE_ALPHA_OPAQUE can be
412 used to indicate those values in a more readable form.
414 While all images have RGB data, not all images have an alpha channel. Before
415 using wxImage::GetAlpha you should check if this image contains an alpha
416 channel with wxImage::HasAlpha. Currently the BMP, PNG, TGA, and TIFF format
417 handlers have full alpha channel support for loading so if you want to use
418 alpha you have to use one of these formats. If you initialize the image
419 alpha channel yourself using wxImage::SetAlpha, you should save it in
420 either PNG, TGA, or TIFF format to avoid losing it as these are the only
421 handlers that currently support saving with alpha.
424 @section image_handlers Available image handlers
426 The following image handlers are available.
427 wxBMPHandler is always installed by default.
428 To use other image formats, install the appropriate handler with
429 wxImage::AddHandler or call ::wxInitAllImageHandlers().
431 - wxBMPHandler: For loading (including alpha support) and saving, always installed.
432 - wxPNGHandler: For loading and saving. Includes alpha support.
433 - wxJPEGHandler: For loading and saving.
434 - wxGIFHandler: For loading and saving (see below).
435 - wxPCXHandler: For loading and saving (see below).
436 - wxPNMHandler: For loading and saving (see below).
437 - wxTIFFHandler: For loading and saving. Includes alpha support.
438 - wxTGAHandler: For loading and saving. Includes alpha support.
439 - wxIFFHandler: For loading only.
440 - wxXPMHandler: For loading and saving.
441 - wxICOHandler: For loading and saving.
442 - wxCURHandler: For loading and saving.
443 - wxANIHandler: For loading only.
445 When saving in PCX format, wxPCXHandler will count the number of different
446 colours in the image; if there are 256 or less colours, it will save as 8 bit,
447 else it will save as 24 bit.
449 Loading PNMs only works for ASCII or raw RGB images.
450 When saving in PNM format, wxPNMHandler will always save as raw RGB.
452 Saving GIFs requires images of maximum 8 bpp (see wxQuantize), and the alpha channel converted to a mask (see wxImage::ConvertAlphaToMask).
453 Saving an animated GIF requires images of the same size (see wxGIFHandler::SaveAnimation)
461 @see wxBitmap, wxInitAllImageHandlers(), wxPixelData
463 class wxImage
: public wxObject
467 A simple class which stores red, green and blue values as 8 bit unsigned integers
468 in the range of 0-255.
474 Constructor for RGBValue, an object that contains values for red, green
475 and blue which represent the value of a color.
477 It is used by wxImage::HSVtoRGB and wxImage::RGBtoHSV, which convert
478 between HSV color space and RGB color space.
480 RGBValue(unsigned char r
=0, unsigned char g
=0, unsigned char b
=0);
488 A simple class which stores hue, saturation and value as doubles in the range 0.0-1.0.
494 Constructor for HSVValue, an object that contains values for hue, saturation
495 and value which represent the value of a color.
497 It is used by wxImage::HSVtoRGB() and wxImage::RGBtoHSV(), which convert
498 between HSV color space and RGB color space.
500 HSVValue(double h
=0.0, double s
=0.0, double v
=0.0);
508 Creates an empty wxImage object without an alpha channel.
513 Creates an image with the given size and clears it if requested.
515 Does not create an alpha channel.
518 Specifies the width of the image.
520 Specifies the height of the image.
522 If @true, initialize the image to black.
524 wxImage(int width
, int height
, bool clear
= true);
529 wxImage(const wxSize
& sz
, bool clear
= true);
532 Creates an image from data in memory. If @a static_data is @false
533 then the wxImage will take ownership of the data and free it
534 afterwards. For this, it has to be allocated with @e malloc.
537 Specifies the width of the image.
539 Specifies the height of the image.
541 A pointer to RGB data
543 Indicates if the data should be free'd after use
546 wxImage(int width
, int height
, unsigned char* data
, bool static_data
= false);
551 wxImage(const wxSize
& sz
, unsigned char* data
, bool static_data
= false);
554 Creates an image from data in memory. If @a static_data is @false
555 then the wxImage will take ownership of the data and free it
556 afterwards. For this, it has to be allocated with @e malloc.
559 Specifies the width of the image.
561 Specifies the height of the image.
563 A pointer to RGB data
565 A pointer to alpha-channel data
567 Indicates if the data should be free'd after use
570 wxImage(int width
, int height
, unsigned char* data
, unsigned char* alpha
,
571 bool static_data
= false );
576 wxImage(const wxSize
& sz
, unsigned char* data
, unsigned char* alpha
,
577 bool static_data
= false);
580 Creates an image from XPM data.
583 A pointer to XPM image data.
586 Not supported by wxPerl.
589 wxImage(const char* const* xpmData
);
592 Creates an image from a file.
595 Name of the file from which to load the image.
597 May be one of the following:
598 @li wxBITMAP_TYPE_BMP: Load a Windows bitmap file.
599 @li wxBITMAP_TYPE_GIF: Load a GIF bitmap file.
600 @li wxBITMAP_TYPE_JPEG: Load a JPEG bitmap file.
601 @li wxBITMAP_TYPE_PNG: Load a PNG bitmap file.
602 @li wxBITMAP_TYPE_PCX: Load a PCX bitmap file.
603 @li wxBITMAP_TYPE_PNM: Load a PNM bitmap file.
604 @li wxBITMAP_TYPE_TIFF: Load a TIFF bitmap file.
605 @li wxBITMAP_TYPE_TGA: Load a TGA bitmap file.
606 @li wxBITMAP_TYPE_XPM: Load a XPM bitmap file.
607 @li wxBITMAP_TYPE_ICO: Load a Windows icon file (ICO).
608 @li wxBITMAP_TYPE_CUR: Load a Windows cursor file (CUR).
609 @li wxBITMAP_TYPE_ANI: Load a Windows animated cursor file (ANI).
610 @li wxBITMAP_TYPE_ANY: Will try to autodetect the format.
612 Index of the image to load in the case that the image file contains
613 multiple images. This is only used by GIF, ICO and TIFF handlers.
614 The default value (-1) means "choose the default image" and is
615 interpreted as the first image (index=0) by the GIF and TIFF handler
616 and as the largest and most colourful one by the ICO handler.
618 @remarks Depending on how wxWidgets has been configured and by which
619 handlers have been loaded, not all formats may be available.
620 Any handler other than BMP must be previously initialized with
621 wxImage::AddHandler or wxInitAllImageHandlers.
624 You can use GetOptionInt() to get the hotspot when loading cursor files:
626 int hotspot_x = image.GetOptionInt(wxIMAGE_OPTION_CUR_HOTSPOT_X);
627 int hotspot_y = image.GetOptionInt(wxIMAGE_OPTION_CUR_HOTSPOT_Y);
632 wxImage(const wxString
& name
, wxBitmapType type
= wxBITMAP_TYPE_ANY
, int index
= -1);
635 Creates an image from a file using MIME-types to specify the type.
638 Name of the file from which to load the image.
640 MIME type string (for example 'image/jpeg')
642 See description in wxImage(const wxString&, wxBitmapType, int) overload.
644 wxImage(const wxString
& name
, const wxString
& mimetype
, int index
= -1);
647 Creates an image from a stream.
650 Opened input stream from which to load the image. Currently,
651 the stream must support seeking.
653 See description in wxImage(const wxString&, wxBitmapType, int) overload.
655 See description in wxImage(const wxString&, wxBitmapType, int) overload.
657 wxImage(wxInputStream
& stream
, wxBitmapType type
= wxBITMAP_TYPE_ANY
, int index
= -1);
660 Creates an image from a stream using MIME-types to specify the type.
663 Opened input stream from which to load the image. Currently,
664 the stream must support seeking.
666 MIME type string (for example 'image/jpeg')
668 See description in wxImage(const wxString&, wxBitmapType, int) overload.
670 wxImage(wxInputStream
& stream
, const wxString
& mimetype
, int index
= -1);
675 See @ref overview_refcount_destruct "reference-counted object destruction"
683 @name Image creation, initialization and deletion functions
688 Returns an identical copy of this image.
690 wxImage
Copy() const;
693 Creates a fresh image.
694 See wxImage::wxImage(int,int,bool) for more info.
696 @return @true if the call succeeded, @false otherwise.
698 bool Create(int width
, int height
, bool clear
= true);
703 bool Create( const wxSize
& sz
, bool clear
= true );
706 Creates a fresh image.
707 See wxImage::wxImage(int,int,unsigned char*,bool) for more info.
709 @return @true if the call succeeded, @false otherwise.
711 bool Create( int width
, int height
, unsigned char* data
, bool static_data
= false );
716 bool Create( const wxSize
& sz
, unsigned char* data
, bool static_data
= false );
719 Creates a fresh image.
720 See wxImage::wxImage(int,int,unsigned char*,unsigned char*,bool) for more info.
722 @return @true if the call succeeded, @false otherwise.
724 bool Create( int width
, int height
, unsigned char* data
, unsigned char* alpha
, bool static_data
= false );
729 bool Create( const wxSize
& sz
, unsigned char* data
, unsigned char* alpha
, bool static_data
= false );
732 Initialize the image data with zeroes (the default) or with the
733 byte value given as @a value.
737 void Clear(unsigned char value
= 0);
740 Destroys the image data.
745 Initializes the image alpha channel data.
747 It is an error to call it if the image already has alpha data.
748 If it doesn't, alpha data will be by default initialized to all pixels
749 being fully opaque. But if the image has a mask colour, all mask pixels
750 will be completely transparent.
758 @name Image manipulation functions
763 Blurs the image in both horizontal and vertical directions by the
764 specified pixel @a blurRadius. This should not be used when using
765 a single mask colour for transparency.
767 @see BlurHorizontal(), BlurVertical()
769 wxImage
Blur(int blurRadius
) const;
772 Blurs the image in the horizontal direction only. This should not be used
773 when using a single mask colour for transparency.
775 @see Blur(), BlurVertical()
777 wxImage
BlurHorizontal(int blurRadius
) const;
780 Blurs the image in the vertical direction only. This should not be used
781 when using a single mask colour for transparency.
783 @see Blur(), BlurHorizontal()
785 wxImage
BlurVertical(int blurRadius
) const;
788 Returns a mirrored copy of the image.
789 The parameter @a horizontally indicates the orientation.
791 wxImage
Mirror(bool horizontally
= true) const;
794 Copy the data of the given @a image to the specified position in this image.
796 void Paste(const wxImage
& image
, int x
, int y
);
799 Replaces the colour specified by @e r1,g1,b1 by the colour @e r2,g2,b2.
801 void Replace(unsigned char r1
, unsigned char g1
,
802 unsigned char b1
, unsigned char r2
,
803 unsigned char g2
, unsigned char b2
);
806 Changes the size of the image in-place by scaling it: after a call to this
807 function,the image will have the given width and height.
809 For a description of the @a quality parameter, see the Scale() function.
810 Returns the (modified) image itself.
814 wxImage
& Rescale(int width
, int height
,
815 wxImageResizeQuality quality
= wxIMAGE_QUALITY_NORMAL
);
818 Changes the size of the image in-place without scaling it by adding either a
819 border with the given colour or cropping as necessary.
821 The image is pasted into a new image with the given @a size and background
822 colour at the position @a pos relative to the upper left of the new image.
824 If @a red = green = blue = -1 then use either the current mask colour
825 if set or find, use, and set a suitable mask colour for any newly exposed
828 @return The (modified) image itself.
832 wxImage
& Resize(const wxSize
& size
, const wxPoint
& pos
, int red
= -1,
833 int green
= -1, int blue
= -1);
836 Rotates the image about the given point, by @a angle radians.
838 Passing @true to @a interpolating results in better image quality, but is slower.
840 If the image has a mask, then the mask colour is used for the uncovered
841 pixels in the rotated image background. Else, black (rgb 0, 0, 0) will be used.
843 Returns the rotated image, leaving this image intact.
845 wxImage
Rotate(double angle
, const wxPoint
& rotationCentre
,
846 bool interpolating
= true,
847 wxPoint
* offsetAfterRotation
= NULL
) const;
850 Returns a copy of the image rotated 90 degrees in the direction
851 indicated by @a clockwise.
853 wxImage
Rotate90(bool clockwise
= true) const;
856 Returns a copy of the image rotated by 180 degrees.
860 wxImage
Rotate180() const;
863 Rotates the hue of each pixel in the image by @e angle, which is a double in
864 the range of -1.0 to +1.0, where -1.0 corresponds to -360 degrees and +1.0
865 corresponds to +360 degrees.
867 void RotateHue(double angle
);
870 Returns a scaled version of the image.
872 This is also useful for scaling bitmaps in general as the only other way
873 to scale bitmaps is to blit a wxMemoryDC into another wxMemoryDC.
875 The parameter @a quality determines what method to use for resampling
876 the image, see wxImageResizeQuality documentation.
878 It should be noted that although using @c wxIMAGE_QUALITY_HIGH produces much nicer
879 looking results it is a slower method. Downsampling will use the box averaging
880 method which seems to operate very fast. If you are upsampling larger images using
881 this method you will most likely notice that it is a bit slower and in extreme
882 cases it will be quite substantially slower as the bicubic algorithm has to process a
885 It should also be noted that the high quality scaling may not work as expected
886 when using a single mask colour for transparency, as the scaling will blur the
887 image and will therefore remove the mask partially. Using the alpha channel
892 // get the bitmap from somewhere
895 // rescale it to have size of 32*32
896 if ( bmp.GetWidth() != 32 || bmp.GetHeight() != 32 )
898 wxImage image = bmp.ConvertToImage();
899 bmp = wxBitmap(image.Scale(32, 32));
901 // another possibility:
902 image.Rescale(32, 32);
909 wxImage
Scale(int width
, int height
,
910 wxImageResizeQuality quality
= wxIMAGE_QUALITY_NORMAL
) const;
913 Returns a resized version of this image without scaling it by adding either a
914 border with the given colour or cropping as necessary.
916 The image is pasted into a new image with the given @a size and background
917 colour at the position @a pos relative to the upper left of the new image.
919 If @a red = green = blue = -1 then the areas of the larger image not covered
920 by this image are made transparent by filling them with the image mask colour
921 (which will be allocated automatically if it isn't currently set).
923 Otherwise, the areas will be filled with the colour with the specified RGB components.
927 wxImage
Size(const wxSize
& size
, const wxPoint
& pos
, int red
= -1,
928 int green
= -1, int blue
= -1) const;
934 @name Conversion functions
939 If the image has alpha channel, this method converts it to mask.
941 If the image has an alpha channel, all pixels with alpha value less
942 than @a threshold are replaced with the mask colour and the alpha
943 channel is removed. Otherwise nothing is done.
945 The mask colour is chosen automatically using
946 FindFirstUnusedColour() by this function, see the overload below if you
947 this is not appropriate.
949 @return Returns @true on success, @false on error.
951 bool ConvertAlphaToMask(unsigned char threshold
= wxIMAGE_ALPHA_THRESHOLD
);
954 If the image has alpha channel, this method converts it to mask using
955 the specified colour as the mask colour.
957 If the image has an alpha channel, all pixels with alpha value less
958 than @a threshold are replaced with the mask colour and the alpha
959 channel is removed. Otherwise nothing is done.
964 The red component of the mask colour.
966 The green component of the mask colour.
968 The blue component of the mask colour.
970 Pixels with alpha channel values below the given threshold are
971 considered to be transparent, i.e. the corresponding mask pixels
972 are set. Pixels with the alpha values above the threshold are
973 considered to be opaque.
975 @return Returns @true on success, @false on error.
977 bool ConvertAlphaToMask(unsigned char mr
, unsigned char mg
, unsigned char mb
,
978 unsigned char threshold
= wxIMAGE_ALPHA_THRESHOLD
);
981 Returns a greyscale version of the image.
983 The returned image uses the luminance component of the original to
984 calculate the greyscale. Defaults to using the standard ITU-T BT.601
985 when converting to YUV, where every pixel equals
986 (R * @a weight_r) + (G * @a weight_g) + (B * @a weight_b).
988 wxImage
ConvertToGreyscale(double weight_r
, double weight_g
, double weight_b
) const;
991 Returns a greyscale version of the image.
994 wxImage
ConvertToGreyscale() const;
997 Returns monochromatic version of the image.
999 The returned image has white colour where the original has @e (r,g,b)
1000 colour and black colour everywhere else.
1002 wxImage
ConvertToMono(unsigned char r
, unsigned char g
, unsigned char b
) const;
1005 Returns disabled (dimmed) version of the image.
1008 wxImage
ConvertToDisabled(unsigned char brightness
= 255) const;
1014 @name Miscellaneous functions
1019 Computes the histogram of the image. @a histogram is a reference to
1020 wxImageHistogram object. wxImageHistogram is a specialization of
1021 wxHashMap "template" and is defined as follows:
1024 class WXDLLEXPORT wxImageHistogramEntry
1027 wxImageHistogramEntry() : index(0), value(0) {}
1028 unsigned long index;
1029 unsigned long value;
1032 WX_DECLARE_EXPORTED_HASH_MAP(unsigned long, wxImageHistogramEntry,
1033 wxIntegerHash, wxIntegerEqual,
1037 @return Returns number of colours in the histogram.
1039 unsigned long ComputeHistogram(wxImageHistogram
& histogram
) const;
1042 Finds the first colour that is never used in the image.
1043 The search begins at given initial colour and continues by increasing
1044 R, G and B components (in this order) by 1 until an unused colour is
1045 found or the colour space exhausted.
1047 The parameters @a r, @a g, @a b are pointers to variables to save the colour.
1049 The parameters @a startR, @a startG, @a startB define the initial values
1051 The returned colour will have RGB values equal to or greater than these.
1053 @return Returns @false if there is no unused colour left, @true on success.
1056 This method involves computing the histogram, which is a
1057 computationally intensive operation.
1059 bool FindFirstUnusedColour(unsigned char* r
, unsigned char* g
,
1060 unsigned char* b
, unsigned char startR
= 1,
1061 unsigned char startG
= 0,
1062 unsigned char startB
= 0) const;
1065 Assignment operator, using @ref overview_refcount "reference counting".
1070 @return Returns 'this' object.
1072 wxImage
& operator=(const wxImage
& image
);
1083 Returns pointer to the array storing the alpha values for this image.
1085 This pointer is @NULL for the images without the alpha channel. If the image
1086 does have it, this pointer may be used to directly manipulate the alpha values
1087 which are stored as the RGB ones.
1089 unsigned char* GetAlpha() const;
1092 Returns the image data as an array.
1094 This is most often used when doing direct image manipulation.
1095 The return value points to an array of characters in RGBRGBRGB... format
1096 in the top-to-bottom, left-to-right order, that is the first RGB triplet
1097 corresponds to the first pixel of the first row, the second one ---
1098 to the second pixel of the first row and so on until the end of the first
1099 row, with second row following after it and so on.
1101 You should not delete the returned pointer nor pass it to SetData().
1103 unsigned char* GetData() const;
1106 Return alpha value at given pixel location.
1108 unsigned char GetAlpha(int x
, int y
) const;
1111 Returns the red intensity at the given coordinate.
1113 unsigned char GetRed(int x
, int y
) const;
1116 Returns the green intensity at the given coordinate.
1118 unsigned char GetGreen(int x
, int y
) const;
1121 Returns the blue intensity at the given coordinate.
1123 unsigned char GetBlue(int x
, int y
) const;
1126 Gets the red value of the mask colour.
1128 unsigned char GetMaskRed() const;
1131 Gets the green value of the mask colour.
1133 unsigned char GetMaskGreen() const;
1136 Gets the blue value of the mask colour.
1138 unsigned char GetMaskBlue() const;
1141 Gets the width of the image in pixels.
1143 @see GetHeight(), GetSize()
1145 int GetWidth() const;
1148 Gets the height of the image in pixels.
1150 @see GetWidth(), GetSize()
1152 int GetHeight() const;
1155 Returns the size of the image in pixels.
1159 @see GetHeight(), GetWidth()
1161 wxSize
GetSize() const;
1164 Gets a user-defined string-valued option.
1167 @li @c wxIMAGE_OPTION_FILENAME: The name of the file from which the image
1170 Options specific to wxGIFHandler:
1171 @li @c wxIMAGE_OPTION_GIF_COMMENT: The comment text that is read from
1172 or written to the GIF file. In an animated GIF each frame can have
1173 its own comment. If there is only a comment in the first frame of
1174 a GIF it will not be repeated in other frames.
1177 The name of the option, case-insensitive.
1179 The value of the option or an empty string if not found. Use
1180 HasOption() if an empty string can be a valid option value.
1182 @see SetOption(), GetOptionInt(), HasOption()
1184 wxString
GetOption(const wxString
& name
) const;
1187 Gets a user-defined integer-valued option.
1189 The function is case-insensitive to @a name.
1190 If the given option is not present, the function returns 0.
1191 Use HasOption() if 0 is a possibly valid value for the option.
1194 @li @c wxIMAGE_OPTION_MAX_WIDTH and @c wxIMAGE_OPTION_MAX_HEIGHT: If either
1195 of these options is specified, the loaded image will be scaled down
1196 (preserving its aspect ratio) so that its width is less than the
1197 max width given if it is not 0 @em and its height is less than the
1198 max height given if it is not 0. This is typically used for loading
1199 thumbnails and the advantage of using these options compared to
1200 calling Rescale() after loading is that some handlers (only JPEG
1201 one right now) support rescaling the image during loading which is
1202 vastly more efficient than loading the entire huge image and
1203 rescaling it later (if these options are not supported by the
1204 handler, this is still what happens however). These options must be
1205 set before calling LoadFile() to have any effect.
1207 @li @c wxIMAGE_OPTION_ORIGINAL_WIDTH and @c wxIMAGE_OPTION_ORIGINAL_HEIGHT:
1208 These options will return the original size of the image if either
1209 @c wxIMAGE_OPTION_MAX_WIDTH or @c wxIMAGE_OPTION_MAX_HEIGHT is
1213 @li @c wxIMAGE_OPTION_QUALITY: JPEG quality used when saving. This is an
1214 integer in 0..100 range with 0 meaning very poor and 100 excellent
1215 (but very badly compressed). This option is currently ignored for
1218 @li @c wxIMAGE_OPTION_RESOLUTIONUNIT: The value of this option determines
1219 whether the resolution of the image is specified in centimetres or
1220 inches, see wxImageResolution enum elements.
1222 @li @c wxIMAGE_OPTION_RESOLUTION, @c wxIMAGE_OPTION_RESOLUTIONX and
1223 @c wxIMAGE_OPTION_RESOLUTIONY: These options define the resolution of
1224 the image in the units corresponding to @c wxIMAGE_OPTION_RESOLUTIONUNIT
1225 options value. The first option can be set before saving the image
1226 to set both horizontal and vertical resolution to the same value.
1227 The X and Y options are set by the image handlers if they support
1228 the image resolution (currently BMP, JPEG and TIFF handlers do) and
1229 the image provides the resolution information and can be queried
1230 after loading the image.
1232 Options specific to wxPNGHandler:
1233 @li @c wxIMAGE_OPTION_PNG_FORMAT: Format for saving a PNG file, see
1234 wxImagePNGType for the supported values.
1235 @li @c wxIMAGE_OPTION_PNG_BITDEPTH: Bit depth for every channel (R/G/B/A).
1236 @li @c wxIMAGE_OPTION_PNG_FILTER: Filter for saving a PNG file, see libpng
1237 (http://www.libpng.org/pub/png/libpng-1.2.5-manual.html) for possible values
1238 (e.g. PNG_FILTER_NONE, PNG_FILTER_SUB, PNG_FILTER_UP, etc).
1239 @li @c wxIMAGE_OPTION_PNG_COMPRESSION_LEVEL: Compression level (0..9) for
1240 saving a PNG file. An high value creates smaller-but-slower PNG file.
1241 Note that unlike other formats (e.g. JPEG) the PNG format is always
1242 lossless and thus this compression level doesn't tradeoff the image
1244 @li @c wxIMAGE_OPTION_PNG_COMPRESSION_MEM_LEVEL: Compression memory usage
1245 level (1..9) for saving a PNG file. An high value means the saving
1246 process consumes more memory, but may create smaller PNG file.
1247 @li @c wxIMAGE_OPTION_PNG_COMPRESSION_STRATEGY: Possible values are 0 for
1248 default strategy, 1 for filter, and 2 for Huffman-only.
1249 You can use OptiPNG (http://optipng.sourceforge.net/) to get a suitable
1250 value for your application.
1251 @li @c wxIMAGE_OPTION_PNG_COMPRESSION_BUFFER_SIZE: Internal buffer size
1252 (in bytes) for saving a PNG file. Ideally this should be as big as
1253 the resulting PNG file. Use this option if your application produces
1254 images with small size variation.
1256 Options specific to wxTIFFHandler:
1257 @li @c wxIMAGE_OPTION_TIFF_BITSPERSAMPLE: Number of bits per
1258 sample (channel). Currently values of 1 and 8 are supported. A
1259 value of 1 results in a black and white image. A value of 8 (the
1260 default) can mean greyscale or RGB, depending on the value of
1261 @c wxIMAGE_OPTION_TIFF_SAMPLESPERPIXEL.
1262 @li @c wxIMAGE_OPTION_TIFF_SAMPLESPERPIXEL: Number of samples
1263 (channels) per pixel. Currently values of 1 and 3 are supported.
1264 A value of 1 results in either a greyscale (by default) or black and
1265 white image, depending on the value of
1266 @c wxIMAGE_OPTION_TIFF_BITSPERSAMPLE. A value of 3 (the default)
1267 will result in an RGB image.
1268 @li @c wxIMAGE_OPTION_TIFF_COMPRESSION: Compression type. By default
1269 it is set to 1 (COMPRESSION_NONE). Typical other values are
1270 5 (COMPRESSION_LZW) and 7 (COMPRESSION_JPEG). See tiff.h for more
1272 @li @c wxIMAGE_OPTION_TIFF_PHOTOMETRIC: Specifies the photometric
1273 interpretation. By default it is set to 2 (PHOTOMETRIC_RGB) for RGB
1274 images and 0 (PHOTOMETRIC_MINISWHITE) for greyscale or black and
1275 white images. It can also be set to 1 (PHOTOMETRIC_MINISBLACK) to
1276 treat the lowest value as black and highest as white.
1277 If you want a greyscale image it is also sufficient to only specify
1278 @c wxIMAGE_OPTION_TIFF_PHOTOMETRIC and set it to either
1279 PHOTOMETRIC_MINISWHITE or PHOTOMETRIC_MINISBLACK. The other values
1283 Be careful when combining the options @c wxIMAGE_OPTION_TIFF_SAMPLESPERPIXEL,
1284 @c wxIMAGE_OPTION_TIFF_BITSPERSAMPLE, and @c wxIMAGE_OPTION_TIFF_PHOTOMETRIC.
1285 While some measures are taken to prevent illegal combinations and/or
1286 values, it is still easy to abuse them and come up with invalid
1287 results in the form of either corrupted images or crashes.
1290 The name of the option, case-insensitive.
1292 The value of the option or 0 if not found.
1293 Use HasOption() if 0 can be a valid option value.
1295 @see SetOption(), GetOption()
1297 int GetOptionInt(const wxString
& name
) const;
1300 Get the current mask colour or find a suitable unused colour that could be
1301 used as a mask colour. Returns @true if the image currently has a mask.
1303 bool GetOrFindMaskColour(unsigned char* r
, unsigned char* g
,
1304 unsigned char* b
) const;
1307 Returns the palette associated with the image.
1308 Currently the palette is only used when converting to wxBitmap under Windows.
1310 Some of the wxImage handlers have been modified to set the palette if
1311 one exists in the image file (usually 256 or less colour images in
1314 const wxPalette
& GetPalette() const;
1317 Returns a sub image of the current one as long as the rect belongs entirely
1320 wxImage
GetSubImage(const wxRect
& rect
) const;
1323 Gets the type of image found by LoadFile() or specified with SaveFile().
1327 wxBitmapType
GetType() const;
1330 Returns @true if this image has alpha channel, @false otherwise.
1332 @see GetAlpha(), SetAlpha()
1334 bool HasAlpha() const;
1337 Returns @true if there is a mask active, @false otherwise.
1339 bool HasMask() const;
1342 Returns @true if the given option is present.
1343 The function is case-insensitive to @a name.
1345 The lists of the currently supported options are in GetOption() and
1346 GetOptionInt() function docs.
1348 @see SetOption(), GetOption(), GetOptionInt()
1350 bool HasOption(const wxString
& name
) const;
1353 Returns @true if image data is present.
1358 Returns @true if the given pixel is transparent, i.e.\ either has the mask
1359 colour if this image has a mask or if this image has alpha channel and alpha
1360 value of this pixel is strictly less than @a threshold.
1362 bool IsTransparent(int x
, int y
,
1363 unsigned char threshold
= wxIMAGE_ALPHA_THRESHOLD
) const;
1369 @name Loading and saving functions
1374 Loads an image from an input stream.
1377 Opened input stream from which to load the image.
1378 Currently, the stream must support seeking.
1380 May be one of the following:
1381 @li wxBITMAP_TYPE_BMP: Load a Windows bitmap file.
1382 @li wxBITMAP_TYPE_GIF: Load a GIF bitmap file.
1383 @li wxBITMAP_TYPE_JPEG: Load a JPEG bitmap file.
1384 @li wxBITMAP_TYPE_PNG: Load a PNG bitmap file.
1385 @li wxBITMAP_TYPE_PCX: Load a PCX bitmap file.
1386 @li wxBITMAP_TYPE_PNM: Load a PNM bitmap file.
1387 @li wxBITMAP_TYPE_TIFF: Load a TIFF bitmap file.
1388 @li wxBITMAP_TYPE_TGA: Load a TGA bitmap file.
1389 @li wxBITMAP_TYPE_XPM: Load a XPM bitmap file.
1390 @li wxBITMAP_TYPE_ICO: Load a Windows icon file (ICO).
1391 @li wxBITMAP_TYPE_CUR: Load a Windows cursor file (CUR).
1392 @li wxBITMAP_TYPE_ANI: Load a Windows animated cursor file (ANI).
1393 @li wxBITMAP_TYPE_ANY: Will try to autodetect the format.
1395 Index of the image to load in the case that the image file contains
1396 multiple images. This is only used by GIF, ICO and TIFF handlers.
1397 The default value (-1) means "choose the default image" and is
1398 interpreted as the first image (index=0) by the GIF and TIFF handler
1399 and as the largest and most colourful one by the ICO handler.
1401 @return @true if the operation succeeded, @false otherwise.
1402 If the optional index parameter is out of range, @false is
1403 returned and a call to wxLogError() takes place.
1405 @remarks Depending on how wxWidgets has been configured, not all formats
1409 You can use GetOptionInt() to get the hotspot when loading cursor files:
1411 int hotspot_x = image.GetOptionInt(wxIMAGE_OPTION_CUR_HOTSPOT_X);
1412 int hotspot_y = image.GetOptionInt(wxIMAGE_OPTION_CUR_HOTSPOT_Y);
1417 virtual bool LoadFile(wxInputStream
& stream
,
1418 wxBitmapType type
= wxBITMAP_TYPE_ANY
,
1422 Loads an image from a file.
1423 If no handler type is provided, the library will try to autodetect the format.
1426 Name of the file from which to load the image.
1428 See the description in the LoadFile(wxInputStream&, wxBitmapType, int) overload.
1430 See the description in the LoadFile(wxInputStream&, wxBitmapType, int) overload.
1432 virtual bool LoadFile(const wxString
& name
,
1433 wxBitmapType type
= wxBITMAP_TYPE_ANY
,
1437 Loads an image from a file.
1438 If no handler type is provided, the library will try to autodetect the format.
1441 Name of the file from which to load the image.
1443 MIME type string (for example 'image/jpeg')
1445 See the description in the LoadFile(wxInputStream&, wxBitmapType, int) overload.
1447 virtual bool LoadFile(const wxString
& name
, const wxString
& mimetype
,
1451 Loads an image from an input stream.
1454 Opened input stream from which to load the image.
1455 Currently, the stream must support seeking.
1457 MIME type string (for example 'image/jpeg')
1459 See the description in the LoadFile(wxInputStream&, wxBitmapType, int) overload.
1461 virtual bool LoadFile(wxInputStream
& stream
, const wxString
& mimetype
,
1465 Saves an image in the given stream.
1468 Opened output stream to save the image to.
1472 @return @true if the operation succeeded, @false otherwise.
1474 @remarks Depending on how wxWidgets has been configured, not all formats
1478 You can use SetOption() to set the hotspot when saving an image
1479 into a cursor file (default hotspot is in the centre of the image):
1481 image.SetOption(wxIMAGE_OPTION_CUR_HOTSPOT_X, hotspotX);
1482 image.SetOption(wxIMAGE_OPTION_CUR_HOTSPOT_Y, hotspotY);
1487 virtual bool SaveFile(wxOutputStream
& stream
,
1488 const wxString
& mimetype
) const;
1491 Saves an image in the named file.
1494 Name of the file to save the image to.
1496 Currently these types can be used:
1497 @li wxBITMAP_TYPE_BMP: Save a BMP image file.
1498 @li wxBITMAP_TYPE_JPEG: Save a JPEG image file.
1499 @li wxBITMAP_TYPE_PNG: Save a PNG image file.
1500 @li wxBITMAP_TYPE_PCX: Save a PCX image file
1501 (tries to save as 8-bit if possible, falls back to 24-bit otherwise).
1502 @li wxBITMAP_TYPE_PNM: Save a PNM image file (as raw RGB always).
1503 @li wxBITMAP_TYPE_TIFF: Save a TIFF image file.
1504 @li wxBITMAP_TYPE_XPM: Save a XPM image file.
1505 @li wxBITMAP_TYPE_ICO: Save a Windows icon file (ICO).
1506 The size may be up to 255 wide by 127 high. A single image is saved
1507 in 8 colors at the size supplied.
1508 @li wxBITMAP_TYPE_CUR: Save a Windows cursor file (CUR).
1510 virtual bool SaveFile(const wxString
& name
, wxBitmapType type
) const;
1513 Saves an image in the named file.
1516 Name of the file to save the image to.
1520 virtual bool SaveFile(const wxString
& name
, const wxString
& mimetype
) const;
1523 Saves an image in the named file.
1525 File type is determined from the extension of the file name.
1526 Note that this function may fail if the extension is not recognized!
1527 You can use one of the forms above to save images to files with
1528 non-standard extensions.
1531 Name of the file to save the image to.
1533 virtual bool SaveFile(const wxString
& name
) const;
1536 Saves an image in the given stream.
1539 Opened output stream to save the image to.
1543 virtual bool SaveFile(wxOutputStream
& stream
, wxBitmapType type
) const;
1555 This function is similar to SetData() and has similar restrictions.
1557 The pointer passed to it may however be @NULL in which case the function
1558 will allocate the alpha array internally -- this is useful to add alpha
1559 channel data to an image which doesn't have any.
1561 If the pointer is not @NULL, it must have one byte for each image pixel
1562 and be allocated with malloc().
1563 wxImage takes ownership of the pointer and will free it unless @a static_data
1564 parameter is set to @true -- in this case the caller should do it.
1566 void SetAlpha(unsigned char* alpha
= NULL
,
1567 bool static_data
= false);
1570 Sets the alpha value for the given pixel.
1571 This function should only be called if the image has alpha channel data,
1572 use HasAlpha() to check for this.
1574 void SetAlpha(int x
, int y
, unsigned char alpha
);
1577 Removes the alpha channel from the image.
1579 This function should only be called if the image has alpha channel data,
1580 use HasAlpha() to check for this.
1587 Sets the image data without performing checks.
1589 The data given must have the size (width*height*3) or results will be
1590 unexpected. Don't use this method if you aren't sure you know what you
1593 The data must have been allocated with @c malloc(), @b NOT with
1596 If @a static_data is @false, after this call the pointer to the data is
1597 owned by the wxImage object, that will be responsible for deleting it.
1598 Do not pass to this function a pointer obtained through GetData().
1600 void SetData(unsigned char* data
, bool static_data
= false);
1605 void SetData(unsigned char* data
, int new_width
, int new_height
,
1606 bool static_data
= false);
1609 Specifies whether there is a mask or not.
1611 The area of the mask is determined by the current mask colour.
1613 void SetMask(bool hasMask
= true);
1616 Sets the mask colour for this image (and tells the image to use the mask).
1618 void SetMaskColour(unsigned char red
, unsigned char green
,
1619 unsigned char blue
);
1622 Sets image's mask so that the pixels that have RGB value of mr,mg,mb in
1623 mask will be masked in the image.
1625 This is done by first finding an unused colour in the image, setting
1626 this colour as the mask colour and then using this colour to draw all
1627 pixels in the image who corresponding pixel in mask has given RGB value.
1629 The parameter @a mask is the mask image to extract mask shape from.
1630 It must have the same dimensions as the image.
1632 The parameters @a mr, @a mg, @a mb are the RGB values of the pixels in
1633 mask that will be used to create the mask.
1635 @return Returns @false if mask does not have same dimensions as the image
1636 or if there is no unused colour left. Returns @true if the mask
1637 was successfully applied.
1640 Note that this method involves computing the histogram, which is a
1641 computationally intensive operation.
1643 bool SetMaskFromImage(const wxImage
& mask
, unsigned char mr
,
1648 Sets a user-defined option. The function is case-insensitive to @a name.
1650 For example, when saving as a JPEG file, the option @b quality is
1651 used, which is a number between 0 and 100 (0 is terrible, 100 is very good).
1653 The lists of the currently supported options are in GetOption() and
1654 GetOptionInt() function docs.
1656 @see GetOption(), GetOptionInt(), HasOption()
1658 void SetOption(const wxString
& name
, const wxString
& value
);
1663 void SetOption(const wxString
& name
, int value
);
1666 Associates a palette with the image.
1668 The palette may be used when converting wxImage to wxBitmap (MSW only at present)
1669 or in file save operations (none as yet).
1671 void SetPalette(const wxPalette
& palette
);
1674 Sets the colour of the pixels within the given rectangle.
1676 This routine performs bounds-checks for the coordinate so it can be considered
1677 a safe way to manipulate the data.
1679 void SetRGB(const wxRect
& rect
,
1681 unsigned char green
,
1682 unsigned char blue
);
1685 Set the type of image returned by GetType().
1687 This method is mostly used internally by the library but can also be
1688 called from the user code if the image was created from data in the
1689 given bitmap format without using LoadFile() (which would set the type
1690 correctly automatically).
1692 Notice that the image must be created before this function is called.
1697 One of bitmap type constants, @c wxBITMAP_TYPE_INVALID is a valid
1698 value for it and can be used to reset the bitmap type to default
1699 but @c wxBITMAP_TYPE_MAX is not allowed here.
1701 void SetType(wxBitmapType type
);
1708 @name Handler management functions
1713 Register an image handler.
1715 Typical example of use:
1717 wxImage::AddHandler(new wxPNGHandler);
1720 See @ref image_handlers for a list of the available handlers. You can
1721 also use ::wxInitAllImageHandlers() to add handlers for all the image
1722 formats supported by wxWidgets at once.
1725 A heap-allocated handler object which will be deleted by wxImage
1726 if it is removed later by RemoveHandler() or at program shutdown.
1728 static void AddHandler(wxImageHandler
* handler
);
1731 Deletes all image handlers.
1732 This function is called by wxWidgets on exit.
1734 static void CleanUpHandlers();
1737 Finds the handler with the given name.
1742 @return A pointer to the handler if found, @NULL otherwise.
1746 static wxImageHandler
* FindHandler(const wxString
& name
);
1749 Finds the handler associated with the given extension and type.
1752 The file extension, such as "bmp".
1754 The image type; one of the ::wxBitmapType values.
1756 @return A pointer to the handler if found, @NULL otherwise.
1760 static wxImageHandler
* FindHandler(const wxString
& extension
,
1761 wxBitmapType imageType
);
1764 Finds the handler associated with the given image type.
1767 The image type; one of the ::wxBitmapType values.
1769 @return A pointer to the handler if found, @NULL otherwise.
1773 static wxImageHandler
* FindHandler(wxBitmapType imageType
);
1776 Finds the handler associated with the given MIME type.
1781 @return A pointer to the handler if found, @NULL otherwise.
1785 static wxImageHandler
* FindHandlerMime(const wxString
& mimetype
);
1788 Returns the static list of image format handlers.
1792 static wxList
& GetHandlers();
1795 Internal use only. Adds standard image format handlers.
1796 It only install wxBMPHandler for the time being, which is used by wxBitmap.
1798 This function is called by wxWidgets on startup, and shouldn't be called by
1801 @see wxImageHandler, wxInitAllImageHandlers(), wxQuantize
1803 static void InitStandardHandlers();
1806 Adds a handler at the start of the static list of format handlers.
1809 A new image format handler object. There is usually only one instance
1810 of a given handler class in an application session.
1814 static void InsertHandler(wxImageHandler
* handler
);
1817 Finds the handler with the given name, and removes it.
1819 The handler is also deleted.
1824 @return @true if the handler was found and removed, @false otherwise.
1828 static bool RemoveHandler(const wxString
& name
);
1834 Returns @true if at least one of the available image handlers can read
1835 the file with the given name.
1837 See wxImageHandler::CanRead for more info.
1839 static bool CanRead(const wxString
& filename
);
1842 Returns @true if at least one of the available image handlers can read
1843 the data in the given stream.
1845 See wxImageHandler::CanRead for more info.
1847 static bool CanRead(wxInputStream
& stream
);
1851 If the image file contains more than one image and the image handler is
1852 capable of retrieving these individually, this function will return the
1853 number of available images.
1855 For the overload taking the parameter @a filename, that's the name
1856 of the file to query.
1857 For the overload taking the parameter @a stream, that's the opened input
1858 stream with image data.
1860 See wxImageHandler::GetImageCount() for more info.
1862 The parameter @a type may be one of the following values:
1863 @li wxBITMAP_TYPE_BMP: Load a Windows bitmap file.
1864 @li wxBITMAP_TYPE_GIF: Load a GIF bitmap file.
1865 @li wxBITMAP_TYPE_JPEG: Load a JPEG bitmap file.
1866 @li wxBITMAP_TYPE_PNG: Load a PNG bitmap file.
1867 @li wxBITMAP_TYPE_PCX: Load a PCX bitmap file.
1868 @li wxBITMAP_TYPE_PNM: Load a PNM bitmap file.
1869 @li wxBITMAP_TYPE_TIFF: Load a TIFF bitmap file.
1870 @li wxBITMAP_TYPE_TGA: Load a TGA bitmap file.
1871 @li wxBITMAP_TYPE_XPM: Load a XPM bitmap file.
1872 @li wxBITMAP_TYPE_ICO: Load a Windows icon file (ICO).
1873 @li wxBITMAP_TYPE_CUR: Load a Windows cursor file (CUR).
1874 @li wxBITMAP_TYPE_ANI: Load a Windows animated cursor file (ANI).
1875 @li wxBITMAP_TYPE_ANY: Will try to autodetect the format.
1877 @return Number of available images. For most image handlers, this is 1
1878 (exceptions are TIFF and ICO formats as well as animated GIFs
1879 for which this function returns the number of frames in the
1882 static int GetImageCount(const wxString
& filename
,
1883 wxBitmapType type
= wxBITMAP_TYPE_ANY
);
1884 static int GetImageCount(wxInputStream
& stream
,
1885 wxBitmapType type
= wxBITMAP_TYPE_ANY
);
1889 Iterates all registered wxImageHandler objects, and returns a string containing
1890 file extension masks suitable for passing to file open/save dialog boxes.
1892 @return The format of the returned string is @c "(*.ext1;*.ext2)|*.ext1;*.ext2".
1893 It is usually a good idea to prepend a description before passing
1894 the result to the dialog.
1897 wxFileDialog FileDlg( this, "Choose Image", ::wxGetCwd(), "",
1898 _("Image Files ") + wxImage::GetImageExtWildcard(),
1904 static wxString
GetImageExtWildcard();
1907 Converts a color in RGB color space to HSV color space.
1909 static wxImage::HSVValue
RGBtoHSV(const wxImage::RGBValue
& rgb
);
1912 Converts a color in HSV color space to RGB color space.
1914 static wxImage::RGBValue
HSVtoRGB(const wxImage::HSVValue
& hsv
);
1918 class wxImageHistogram
: public wxImageHistogramBase
1923 // get the key in the histogram for the given RGB values
1924 static unsigned long MakeKey(unsigned char r
,
1928 // find first colour that is not used in the image and has higher
1929 // RGB values than RGB(startR, startG, startB)
1931 // returns true and puts this colour in r, g, b (each of which may be NULL)
1932 // on success or returns false if there are no more free colours
1933 bool FindFirstUnusedColour(unsigned char *r
,
1936 unsigned char startR
= 1,
1937 unsigned char startG
= 0,
1938 unsigned char startB
= 0 ) const;
1942 An instance of an empty image without an alpha channel.
1944 wxImage wxNullImage
;
1947 // ============================================================================
1948 // Global functions/macros
1949 // ============================================================================
1951 /** @addtogroup group_funcmacro_appinitterm */
1955 Initializes all available image handlers.
1957 This function calls wxImage::AddHandler() for all the available image
1958 handlers (see @ref image_handlers for the full list). Calling it is the
1959 simplest way to initialize wxImage but it creates and registers even the
1960 handlers your program may not use. If you want to avoid the overhead of
1961 doing this you need to call wxImage::AddHandler() manually just for the
1962 handlers that you do want to use.
1964 @see wxImage, wxImageHandler
1968 void wxInitAllImageHandlers();