1 \section{\class{wxImage
}}\label{wximage
}
3 This class encapsulates a platform-independent image. An image can be created
4 from data, or using
\helpref{wxBitmap::ConvertToImage
}{wxbitmapconverttoimage
}. An image
5 can be loaded from a file in a variety of formats, and is extensible to new formats
6 via image format handlers. Functions are available to set and get image bits, so
7 it can be used for basic image manipulation.
9 A wxImage cannot (currently) be drawn directly to a
\helpref{wxDC
}{wxdc
}. Instead,
10 a platform-specific
\helpref{wxBitmap
}{wxbitmap
} object must be created from it using
11 the
\helpref{wxBitmap::wxBitmap(wxImage,int depth)
}{wxbitmapconstr
} constructor.
13 be drawn in a device context, using
\helpref{wxDC::DrawBitmap
}{wxdcdrawbitmap
}.
15 One colour value of the image may be used as a mask colour which will lead to the automatic
16 creation of a
\helpref{wxMask
}{wxmask
} object associated to the bitmap object.
18 \wxheading{Alpha channel support
}
20 Starting from wxWidgets
2.5.0 wxImage supports alpha channel data, that is in
21 addition to a byte for the red, green and blue colour components for each pixel
22 it also stores a byte representing the pixel opacity. The alpha value of $
0$
23 corresponds to a transparent pixel (null opacity) while the value of $
255$
24 means that the pixel is
100\% opaque.
26 Unlike the RGB data, not all images have the alpha channel and before using
27 \helpref{GetAlpha
}{wximagegetalpha
} you should check if this image contains
28 alpha value with
\helpref{HasAlpha
}{wximagehasalpha
}. In fact, currently only
29 images loaded from PNG files with transparency information will have alpha
30 channel but support for it will be added to the other formats as well (as well
31 as support for saving images with alpha channel which is not still implemented
34 \wxheading{Available image handlers
}
36 The following image handlers are available.
{\bf wxBMPHandler
} is always
37 installed by default. To use other image formats, install the appropriate
38 handler with
\helpref{wxImage::AddHandler
}{wximageaddhandler
} or
39 \helpref{wxInitAllImageHandlers
}{wxinitallimagehandlers
}.
43 \twocolitem{\indexit{wxBMPHandler
}}{For loading and saving, always installed.
}
44 \twocolitem{\indexit{wxPNGHandler
}}{For loading (including alpha support) and saving.
}
45 \twocolitem{\indexit{wxJPEGHandler
}}{For loading and saving.
}
46 \twocolitem{\indexit{wxGIFHandler
}}{Only for loading, due to legal issues.
}
47 \twocolitem{\indexit{wxPCXHandler
}}{For loading and saving (see below).
}
48 \twocolitem{\indexit{wxPNMHandler
}}{For loading and saving (see below).
}
49 \twocolitem{\indexit{wxTIFFHandler
}}{For loading and saving.
}
50 \twocolitem{\indexit{wxIFFHandler
}}{For loading only.
}
51 \twocolitem{\indexit{wxXPMHandler
}}{For loading and saving.
}
52 \twocolitem{\indexit{wxICOHandler
}}{For loading and saving.
}
53 \twocolitem{\indexit{wxCURHandler
}}{For loading and saving.
}
54 \twocolitem{\indexit{wxANIHandler
}}{For loading only.
}
57 When saving in PCX format,
{\bf wxPCXHandler
} will count the number of
58 different colours in the image; if there are
256 or less colours, it will
59 save as
8 bit, else it will save as
24 bit.
61 Loading PNMs only works for ASCII or raw RGB images. When saving in
62 PNM format,
{\bf wxPNMHandler
} will always save as raw RGB.
64 \wxheading{Derived from
}
66 \helpref{wxObject
}{wxobject
}
68 \wxheading{Include files
}
74 \helpref{wxBitmap
}{wxbitmap
},
75 \helpref{wxInitAllImageHandlers
}{wxinitallimagehandlers
}
77 \latexignore{\rtfignore{\wxheading{Members
}}}
79 \membersection{wxImage::wxImage
}\label{wximageconstr
}
81 \func{}{wxImage
}{\void}
85 \func{}{wxImage
}{\param{const wxImage\&
}{image
}}
89 \func{}{wxImage
}{\param{const wxBitmap\&
}{ bitmap
}}
91 (Deprecated form, use
\helpref{wxBitmap::ConvertToImage
}{wxbitmapconverttoimage
}
92 instead.) Constructs an image from a platform-dependent bitmap. This preserves
93 mask information so that bitmaps and images can be converted back
94 and forth without loss in that respect.
96 \func{}{wxImage
}{\param{int
}{ width
},
\param{int
}{ height
},
\param{bool
}{ clear=true
}}
98 Creates an image with the given width and height. If
{\it clear
} is true, the new image will be initialized to black.
99 Otherwise, the image data will be uninitialized.
101 \func{}{wxImage
}{\param{int
}{ width
},
\param{int
}{ height
},
\param{unsigned char*
}{ data
},
\param{bool
}{ static
\_data=false
}}
103 Creates an image from given data with the given width and height. If
104 {\it static
\_data} is true, then wxImage will not delete the actual
105 image data in its destructor, otherwise it will free it by calling
108 \func{}{wxImage
}{\param{const wxString\&
}{name
},
\param{long
}{ type = wxBITMAP
\_TYPE\_ANY},
\param{int
}{ index = -
1}}
110 \func{}{wxImage
}{\param{const wxString\&
}{name
},
\param{const wxString\&
}{ mimetype
},
\param{int
}{ index = -
1}}
112 Loads an image from a file.
114 \func{}{wxImage
}{\param{wxInputStream\&
}{stream
},
\param{long
}{ type = wxBITMAP
\_TYPE\_ANY},
\param{int
}{ index = -
1}}
116 \func{}{wxImage
}{\param{wxInputStream\&
}{stream
},
\param{const wxString\&
}{ mimetype
},
\param{int
}{ index = -
1}}
118 Loads an image from an input stream.
120 \wxheading{Parameters
}
122 \docparam{width
}{Specifies the width of the image.
}
124 \docparam{height
}{Specifies the height of the image.
}
126 \docparam{name
}{Name of the file from which to load the image.
}
128 \docparam{stream
}{Opened input stream from which to load the image. Currently, the stream must support seeking.
}
130 \docparam{type
}{May be one of the following:
134 \twocolitem{\indexit{wxBITMAP
\_TYPE\_BMP}}{Load a Windows bitmap file.
}
135 \twocolitem{\indexit{wxBITMAP
\_TYPE\_GIF}}{Load a GIF bitmap file.
}
136 \twocolitem{\indexit{wxBITMAP
\_TYPE\_JPEG}}{Load a JPEG bitmap file.
}
137 \twocolitem{\indexit{wxBITMAP
\_TYPE\_PNG}}{Load a PNG bitmap file.
}
138 \twocolitem{\indexit{wxBITMAP
\_TYPE\_PCX}}{Load a PCX bitmap file.
}
139 \twocolitem{\indexit{wxBITMAP
\_TYPE\_PNM}}{Load a PNM bitmap file.
}
140 \twocolitem{\indexit{wxBITMAP
\_TYPE\_TIF}}{Load a TIFF bitmap file.
}
141 \twocolitem{\indexit{wxBITMAP
\_TYPE\_XPM}}{Load a XPM bitmap file.
}
142 \twocolitem{\indexit{wxBITMAP
\_TYPE\_ICO}}{Load a Windows icon file (ICO).
}
143 \twocolitem{\indexit{wxBITMAP
\_TYPE\_CUR}}{Load a Windows cursor file (CUR).
}
144 \twocolitem{\indexit{wxBITMAP
\_TYPE\_ANI}}{Load a Windows animated cursor file (ANI).
}
145 \twocolitem{\indexit{wxBITMAP
\_TYPE\_ANY}}{Will try to autodetect the format.
}
148 \docparam{mimetype
}{MIME type string (for example 'image/jpeg')
}
150 \docparam{index
}{Index of the image to load in the case that the image file contains multiple images.
151 This is only used by GIF, ICO and TIFF handlers. The default value (-
1) means
152 "choose the default image" and is interpreted as the first image (index=
0) by
153 the GIF and TIFF handler and as the largest and most colourful one by the ICO handler.
}
157 Depending on how wxWidgets has been configured, not all formats may be available.
159 Note: any handler other than BMP must be previously
160 initialized with
\helpref{wxImage::AddHandler
}{wximageaddhandler
} or
161 \helpref{wxInitAllImageHandlers
}{wxinitallimagehandlers
}.
163 Note: you can use
\helpref{GetOptionInt
}{wximagegetoptionint
} to get the
164 hotspot for loaded cursor file:
166 int hotspot_x = image.GetOptionInt(wxIMAGE_OPTION_CUR_HOTSPOT_X);
167 int hotspot_y = image.GetOptionInt(wxIMAGE_OPTION_CUR_HOTSPOT_Y);
173 \helpref{wxImage::LoadFile
}{wximageloadfile
}
175 \pythonnote{Constructors supported by wxPython are:
\par
176 \indented{2cm
}{\begin{twocollist
}
177 \twocolitem{{\bf wxImage(name, flag)
}}{Loads an image from a file
}
178 \twocolitem{{\bf wxNullImage()
}}{Create a null image (has no size or
180 \twocolitem{{\bf wxEmptyImage(width, height)
}}{Creates an empty image
182 \twocolitem{{\bf wxImageFromMime(name, mimetype
}}{Creates an image from
183 the given file of the given mimetype
}
184 \twocolitem{{\bf wxImageFromBitmap(bitmap)
}}{Creates an image from a
185 platform-dependent bitmap
}
189 \perlnote{Constructors supported by wxPerl are:
\par
191 \item{Wx::Image->new( bitmap )
}
192 \item{Wx::Image->new( icon )
}
193 \item{Wx::Image->new( width, height )
}
194 \item{Wx::Image->new( width, height, data )
}
195 \item{Wx::Image->new( file, type, index )
}
196 \item{Wx::Image->new( file, mimetype, index )
}
197 \item{Wx::Image->new( stream, type, index )
}
198 \item{Wx::Image->new( stream, mimetype, index )
}
202 \membersection{wxImage::
\destruct{wxImage
}}
204 \func{}{\destruct{wxImage
}}{\void}
208 \membersection{wxImage::AddHandler
}\label{wximageaddhandler
}
210 \func{static void
}{AddHandler
}{\param{wxImageHandler*
}{ handler
}}
212 Adds a handler to the end of the static list of format handlers.
214 \docparam{handler
}{A new image format handler object. There is usually only one instance
215 of a given handler class in an application session.
}
219 \helpref{wxImageHandler
}{wximagehandler
}
221 \func{bool
}{CanRead
}{\param{const wxString\&
}{ filename
}}
223 returns true if the current image handlers can read this file
225 \pythonnote{In wxPython this static method is named
{\tt wxImage
\_AddHandler}.
}
226 \membersection{wxImage::CleanUpHandlers
}
228 \func{static void
}{CleanUpHandlers
}{\void}
230 Deletes all image handlers.
232 This function is called by wxWidgets on exit.
234 \membersection{wxImage::ComputeHistogram
}\label{wximagecomputehistogram
}
236 \constfunc{unsigned long
}{ComputeHistogram
}{\param{wxImageHistogram\&
}{histogram
}}
238 Computes the histogram of the image.
{\it histogram
} is a reference to
239 wxImageHistogram object. wxImageHistogram is a specialization of
240 \helpref{wxHashMap
}{wxhashmap
} "template" and is defined as follows:
243 class WXDLLEXPORT wxImageHistogramEntry
246 wxImageHistogramEntry() : index(
0), value(
0)
{}
251 WX_DECLARE_EXPORTED_HASH_MAP(unsigned long, wxImageHistogramEntry,
252 wxIntegerHash, wxIntegerEqual,
256 \wxheading{Return value
}
258 Returns number of colours in the histogram.
260 \membersection{wxImage::ConvertAlphaToMask
}\label{wximageconvertalphatomask
}
262 \func{bool
}{ConvertAlphaToMask
}{\param{unsigned char
}{ threshold =
128}}
264 If the image has alpha channel, this method converts it to mask. All pixels
265 with alpha value less than
\arg{threshold
} are replaced with mask colour
266 and the alpha channel is removed. Mask colour is chosen automatically using
267 \helpref{FindFirstUnusedColour
}{wximagefindfirstunusedcolour
}.
269 If the image image doesn't have alpha channel,
270 ConvertAlphaToMask does nothing.
272 \wxheading{Return value
}
274 \false if FindFirstUnusedColour returns
\false,
\true otherwise.
276 \membersection{wxImage::ConvertToBitmap
}\label{wximageconverttobitmap
}
278 \constfunc{wxBitmap
}{ConvertToBitmap
}{\void}
280 Deprecated, use equivalent
\helpref{wxBitmap constructor
}{wxbitmapconstr
}
281 (which takes wxImage and depth as its arguments) instead.
283 \membersection{wxImage::ConvertToMono
}\label{wxbitmapconverttomono
}
285 \constfunc{wxImage
}{ConvertToMono
}{\param{unsigned char
}{ r
},
\param{unsigned char
}{ g
},
\param{unsigned char
}{ b
}}
287 Returns monochromatic version of the image. The returned image has white
288 colour where the original has
{\it (r,g,b)
} colour and black colour
291 \membersection{wxImage::Copy
}\label{wximagecopy
}
293 \constfunc{wxImage
}{Copy
}{\void}
295 Returns an identical copy of the image.
297 \membersection{wxImage::Create
}\label{wximagecreate
}
299 \func{bool
}{Create
}{\param{int
}{ width
},
\param{int
}{ height
},
\param{bool
}{ clear=true
}}
301 Creates a fresh image. If
{\it clear
} is true, the new image will be initialized to black.
302 Otherwise, the image data will be uninitialized.
304 \wxheading{Parameters
}
306 \docparam{width
}{The width of the image in pixels.
}
308 \docparam{height
}{The height of the image in pixels.
}
310 \wxheading{Return value
}
312 true if the call succeeded, false otherwise.
314 \membersection{wxImage::Destroy
}\label{wximagedestroy
}
316 \func{bool
}{Destroy
}{\void}
318 Destroys the image data.
320 \membersection{wxImage::FindFirstUnusedColour
}\label{wximagefindfirstunusedcolour
}
322 \func{bool
}{FindFirstUnusedColour
}{\param{unsigned char *
}{ r
},
\param{unsigned char *
}{ g
},
\param{unsigned char *
}{ b
},
\param{unsigned char
}{ startR =
1},
\param{unsigned char
}{ startG =
0},
\param{unsigned char
}{ startB =
0}}
324 \wxheading{Parameters
}
326 \docparam{r,g,b
}{Pointers to variables to save the colour.
}
328 \docparam{startR,startG,startB
}{Initial values of the colour. Returned colour
329 will have RGB values equal to or greater than these.
}
331 Finds the first colour that is never used in the image. The search begins at
332 given initial colour and continues by increasing R, G and B components (in this
333 order) by
1 until an unused colour is found or the colour space exhausted.
335 \wxheading{Return value
}
337 Returns false if there is no unused colour left, true on success.
341 Note that this method involves computing the histogram, which is
342 computationally intensive operation.
344 \membersection{wxImage::FindHandler
}
346 \func{static wxImageHandler*
}{FindHandler
}{\param{const wxString\&
}{name
}}
348 Finds the handler with the given name.
350 \func{static wxImageHandler*
}{FindHandler
}{\param{const wxString\&
}{extension
},
\param{long
}{ imageType
}}
352 Finds the handler associated with the given extension and type.
354 \func{static wxImageHandler*
}{FindHandler
}{\param{long
}{imageType
}}
356 Finds the handler associated with the given image type.
358 \func{static wxImageHandler*
}{FindHandlerMime
}{\param{const wxString\&
}{mimetype
}}
360 Finds the handler associated with the given MIME type.
362 \docparam{name
}{The handler name.
}
364 \docparam{extension
}{The file extension, such as ``bmp".
}
366 \docparam{imageType
}{The image type, such as wxBITMAP
\_TYPE\_BMP.
}
368 \docparam{mimetype
}{MIME type.
}
370 \wxheading{Return value
}
372 A pointer to the handler if found, NULL otherwise.
376 \helpref{wxImageHandler
}{wximagehandler
}
378 \membersection{wxImage::GetImageExtWildcard
}
380 \func{static wxString
}{GetImageExtWildcard
}{\void}
382 Iterates all registered wxImageHandler objects, and returns a string containing file extension masks
383 suitable for passing to file open/save dialog boxes.
385 \wxheading{Return value
}
387 The format of the returned string is "
(*.ext1;*.ext2)|*.ext1;*.ext2".
389 It is usually a good idea to prepend a description before passing the result to the dialog.
394 wxFileDialog FileDlg( this, "Choose Image", ::wxGetWorkingDirectory(), "", _("Image Files ") + wxImage::GetImageExtWildcard(), wxOPEN );
399 \helpref{wxImageHandler}{wximagehandler}
401 \membersection{wxImage::GetAlpha}\label{wximagegetalpha}
403 \constfunc{unsigned char}{GetAlpha}{\param{int}{ x}, \param{int}{ y}}
405 Returns the alpha value for the given pixel. This function may only be called
406 for the images with alpha channel, use \helpref{HasAlpha}{wximagehasalpha} to
409 The returned value is the {\it opacity} of the image, i.e. the value of $0$
410 corresponds to the transparent pixels while the value of $255$ -- to the opaque
413 \constfunc{unsigned char *}{GetAlpha}{\void}
415 Returns pointer to the array storing the alpha values for this image. This
416 pointer is {\tt NULL} for the images without the alpha channel. If the image
417 does have it, this pointer may be used to directly manipulate the alpha values
418 which are stored as the \helpref{RGB}{wximagegetdata} ones.
420 \membersection{wxImage::GetBlue}\label{wximagegetblue}
422 \constfunc{unsigned char}{GetBlue}{\param{int}{ x}, \param{int}{ y}}
424 Returns the blue intensity at the given coordinate.
426 \membersection{wxImage::GetData}\label{wximagegetdata}
428 \constfunc{unsigned char*}{GetData}{\void}
430 Returns the image data as an array. This is most often used when doing
431 direct image manipulation. The return value points to an array of
432 characters in RGBRGBRGB$\ldots$ format in the top-to-bottom, left-to-right
433 order, that is the first RGB triplet corresponds to the pixel $(0, 0)$, the
434 second one --- to $(0, 1)$ and so on.
436 You should not delete the returned pointer nor pass it to
437 \helpref{wxImage::SetData}{wximagesetdata}.
439 \membersection{wxImage::GetGreen}\label{wximagegetgreen}
441 \constfunc{unsigned char}{GetGreen}{\param{int}{ x}, \param{int}{ y}}
443 Returns the green intensity at the given coordinate.
445 \membersection{wxImage::GetImageCount}\label{wximagegetimagecount}
447 \func{static int}{GetImageCount}{\param{const wxString\&}{ filename}, \param{long}{ type = wxBITMAP\_TYPE\_ANY}}
449 \func{static int}{GetImageCount}{\param{wxInputStream\&}{ stream}, \param{long}{ type = wxBITMAP\_TYPE\_ANY}}
451 If the image file contains more than one image and the image handler is capable
452 of retrieving these individually, this function will return the number of
455 \docparam{name}{Name of the file to query.}
457 \docparam{stream}{Opened input stream with image data. Currently, the stream must support seeking.}
459 \docparam{type}{May be one of the following:
463 \twocolitem{\indexit{wxBITMAP\_TYPE\_BMP}}{Load a Windows bitmap file.}
464 \twocolitem{\indexit{wxBITMAP\_TYPE\_GIF}}{Load a GIF bitmap file.}
465 \twocolitem{\indexit{wxBITMAP\_TYPE\_JPEG}}{Load a JPEG bitmap file.}
466 \twocolitem{\indexit{wxBITMAP\_TYPE\_PNG}}{Load a PNG bitmap file.}
467 \twocolitem{\indexit{wxBITMAP\_TYPE\_PCX}}{Load a PCX bitmap file.}
468 \twocolitem{\indexit{wxBITMAP\_TYPE\_PNM}}{Load a PNM bitmap file.}
469 \twocolitem{\indexit{wxBITMAP\_TYPE\_TIF}}{Load a TIFF bitmap file.}
470 \twocolitem{\indexit{wxBITMAP\_TYPE\_XPM}}{Load a XPM bitmap file.}
471 \twocolitem{\indexit{wxBITMAP\_TYPE\_ICO}}{Load a Windows icon file (ICO).}
472 \twocolitem{\indexit{wxBITMAP\_TYPE\_CUR}}{Load a Windows cursor file (CUR).}
473 \twocolitem{\indexit{wxBITMAP\_TYPE\_ANI}}{Load a Windows animated cursor file (ANI).}
474 \twocolitem{\indexit{wxBITMAP\_TYPE\_ANY}}{Will try to autodetect the format.}
477 \wxheading{Return value}
479 Number of available images. For most image handlers, this is 1 (exceptions
480 are TIFF and ICO formats).
482 \membersection{wxImage::GetHandlers}
484 \func{static wxList\&}{GetHandlers}{\void}
486 Returns the static list of image format handlers.
490 \helpref{wxImageHandler}{wximagehandler}
492 \membersection{wxImage::GetHeight}\label{wximagegetheight}
494 \constfunc{int}{GetHeight}{\void}
496 Gets the height of the image in pixels.
498 \membersection{wxImage::GetMaskBlue}\label{wximagegetmaskblue}
500 \constfunc{unsigned char}{GetMaskBlue}{\void}
502 Gets the blue value of the mask colour.
504 \membersection{wxImage::GetMaskGreen}\label{wximagegetmaskgreen}
506 \constfunc{unsigned char}{GetMaskGreen}{\void}
508 Gets the green value of the mask colour.
510 \membersection{wxImage::GetMaskRed}\label{wximagegetmaskred}
512 \constfunc{unsigned char}{GetMaskRed}{\void}
514 Gets the red value of the mask colour.
516 \membersection{wxImage::GetPalette}\label{wximagegetpalette}
518 \constfunc{const wxPalette\&}{GetPalette}{\void}
520 Returns the palette associated with the image. Currently the palette is only
521 used when converting to wxBitmap under Windows.
523 Eventually wxImage handlers will set the palette if one exists in the image file.
525 \membersection{wxImage::GetRed}\label{wximagegetred}
527 \constfunc{unsigned char}{GetRed}{\param{int}{ x}, \param{int}{ y}}
529 Returns the red intensity at the given coordinate.
531 \membersection{wxImage::GetSubImage}\label{wximagegetsubimage}
533 \constfunc{wxImage}{GetSubImage}{\param{const wxRect\&}{ rect}}
535 Returns a sub image of the current one as long as the rect belongs entirely to
538 \membersection{wxImage::GetWidth}\label{wximagegetwidth}
540 \constfunc{int}{GetWidth}{\void}
542 Gets the width of the image in pixels.
546 \helpref{wxImage::GetHeight}{wximagegetheight}
548 \membersection{wxImage::HasAlpha}\label{wximagehasalpha}
550 \constfunc{bool}{HasAlpha}{\void}
552 Returns true if this image has alpha channel, false otherwise.
556 \helpref{GetAlpha}{wximagegetalpha}, \helpref{SetAlpha}{wximagesetalpha}
558 \membersection{wxImage::HasMask}\label{wximagehasmask}
560 \constfunc{bool}{HasMask}{\void}
562 Returns true if there is a mask active, false otherwise.
564 \membersection{wxImage::GetOption}\label{wximagegetoption}
566 \constfunc{wxString}{GetOption}{\param{const wxString\&}{ name}}
568 Gets a user-defined option. The function is case-insensitive to {\it name}.
570 For example, when saving as a JPEG file, the option {\bf quality} is
571 used, which is a number between 0 and 100 (0 is terrible, 100 is very good).
575 \helpref{wxImage::SetOption}{wximagesetoption},\rtfsp
576 \helpref{wxImage::GetOptionInt}{wximagegetoptionint},\rtfsp
577 \helpref{wxImage::HasOption}{wximagehasoption}
579 \membersection{wxImage::GetOptionInt}\label{wximagegetoptionint}
581 \constfunc{int}{GetOptionInt}{\param{const wxString\&}{ name}}
583 Gets a user-defined option as an integer. The function is case-insensitive to {\it name}.
587 \helpref{wxImage::SetOption}{wximagesetoption},\rtfsp
588 \helpref{wxImage::GetOption}{wximagegetoption},\rtfsp
589 \helpref{wxImage::HasOption}{wximagehasoption}
591 \membersection{wxImage::HasOption}\label{wximagehasoption}
593 \constfunc{bool}{HasOption}{\param{const wxString\&}{ name}}
595 Returns true if the given option is present. The function is case-insensitive to {\it name}.
599 \helpref{wxImage::SetOption}{wximagesetoption},\rtfsp
600 \helpref{wxImage::GetOption}{wximagegetoption},\rtfsp
601 \helpref{wxImage::GetOptionInt}{wximagegetoptionint}
603 \membersection{wxImage::InitStandardHandlers}
605 \func{static void}{InitStandardHandlers}{\void}
607 Internal use only. Adds standard image format handlers. It only install BMP
608 for the time being, which is used by wxBitmap.
610 This function is called by wxWidgets on startup, and shouldn't be called by
615 \helpref{wxImageHandler}{wximagehandler},
616 \helpref{wxInitAllImageHandlers}{wxinitallimagehandlers}
618 \membersection{wxImage::InsertHandler}
620 \func{static void}{InsertHandler}{\param{wxImageHandler*}{ handler}}
622 Adds a handler at the start of the static list of format handlers.
624 \docparam{handler}{A new image format handler object. There is usually only one instance
625 of a given handler class in an application session.}
629 \helpref{wxImageHandler}{wximagehandler}
631 \membersection{wxImage::LoadFile}\label{wximageloadfile}
633 \func{bool}{LoadFile}{\param{const wxString\&}{ name}, \param{long}{ type = wxBITMAP\_TYPE\_ANY}, \param{int}{ index = -1}}
635 \func{bool}{LoadFile}{\param{const wxString\&}{ name}, \param{const wxString\&}{ mimetype}, \param{int}{ index = -1}}
637 Loads an image from a file. If no handler type is provided, the library will
638 try to autodetect the format.
640 \func{bool}{LoadFile}{\param{wxInputStream\&}{ stream}, \param{long}{ type}, \param{int}{ index = -1}}
642 \func{bool}{LoadFile}{\param{wxInputStream\&}{ stream}, \param{const wxString\&}{ mimetype}, \param{int}{ index = -1}}
644 Loads an image from an input stream.
646 \wxheading{Parameters}
648 \docparam{name}{Name of the file from which to load the image.}
650 \docparam{stream}{Opened input stream from which to load the image. Currently, the stream must support seeking.}
652 \docparam{type}{One of the following values:
656 \twocolitem{{\bf wxBITMAP\_TYPE\_BMP}}{Load a Windows image file.}
657 \twocolitem{{\bf wxBITMAP\_TYPE\_GIF}}{Load a GIF image file.}
658 \twocolitem{{\bf wxBITMAP\_TYPE\_JPEG}}{Load a JPEG image file.}
659 \twocolitem{{\bf wxBITMAP\_TYPE\_PCX}}{Load a PCX image file.}
660 \twocolitem{{\bf wxBITMAP\_TYPE\_PNG}}{Load a PNG image file.}
661 \twocolitem{{\bf wxBITMAP\_TYPE\_PNM}}{Load a PNM image file.}
662 \twocolitem{{\bf wxBITMAP\_TYPE\_TIF}}{Load a TIFF image file.}
663 \twocolitem{{\bf wxBITMAP\_TYPE\_XPM}}{Load a XPM image file.}
664 \twocolitem{{\bf wxBITMAP\_TYPE\_ICO}}{Load a Windows icon file (ICO).}
665 \twocolitem{{\bf wxBITMAP\_TYPE\_CUR}}{Load a Windows cursor file (CUR).}
666 \twocolitem{\indexit{wxBITMAP\_TYPE\_ANI}}{Load a Windows animated cursor file (ANI).}
667 \twocolitem{{\bf wxBITMAP\_TYPE\_ANY}}{Will try to autodetect the format.}
670 \docparam{mimetype}{MIME type string (for example 'image/jpeg')}
672 \docparam{index}{Index of the image to load in the case that the image file contains multiple images.
673 This is only used by GIF, ICO and TIFF handlers. The default value (-1) means
674 "choose the default image" and is interpreted as the first image (index=0) by
675 the GIF and TIFF handler and as the largest and most colourful one by the ICO handler.}
679 Depending on how wxWidgets has been configured, not all formats may be available.
681 Note: you can use \helpref{GetOptionInt}{wximagegetoptionint} to get the
682 hotspot for loaded cursor file:
684 int hotspot_x = image.GetOptionInt(wxIMAGE_OPTION_CUR_HOTSPOT_X);
685 int hotspot_y = image.GetOptionInt(wxIMAGE_OPTION_CUR_HOTSPOT_Y);
689 \wxheading{Return value}
691 true if the operation succeeded, false otherwise. If the optional index parameter is out of range,
692 false is returned and a call to wxLogError() takes place.
696 \helpref{wxImage::SaveFile}{wximagesavefile}
698 \pythonnote{In place of a single overloaded method name, wxPython
699 implements the following methods:\par
700 \indented{2cm}{\begin{twocollist}
701 \twocolitem{{\bf LoadFile(filename, type)}}{Loads an image of the given
703 \twocolitem{{\bf LoadMimeFile(filename, mimetype)}}{Loads an image of the given
704 mimetype from a file}
708 \perlnote{Methods supported by wxPerl are:\par
710 \item{bitmap->LoadFile( name, type )}
711 \item{bitmap->LoadFile( name, mimetype )}
716 \membersection{wxImage::Ok}\label{wximageok}
718 \constfunc{bool}{Ok}{\void}
720 Returns true if image data is present.
722 \membersection{wxImage::RemoveHandler}
724 \func{static bool}{RemoveHandler}{\param{const wxString\& }{name}}
726 Finds the handler with the given name, and removes it. The handler
729 \docparam{name}{The handler name.}
731 \wxheading{Return value}
733 true if the handler was found and removed, false otherwise.
737 \helpref{wxImageHandler}{wximagehandler}
739 \membersection{wxImage::Mirror}\label{wximagemirror}
741 \constfunc{wxImage}{Mirror}{\param{bool}{ horizontally = true}}
743 Returns a mirrored copy of the image. The parameter {\it horizontally}
744 indicates the orientation.
746 \membersection{wxImage::Replace}\label{wximagereplace}
748 \func{void}{Replace}{\param{unsigned char}{ r1}, \param{unsigned char}{ g1}, \param{unsigned char}{ b1},
749 \param{unsigned char}{ r2}, \param{unsigned char}{ g2}, \param{unsigned char}{ b2}}
751 Replaces the colour specified by {\it r1,g1,b1} by the colour {\it r2,g2,b2}.
753 \membersection{wxImage::Rescale}\label{wximagerescale}
755 \func{wxImage \&}{Rescale}{\param{int}{ width}, \param{int}{ height}}
757 Changes the size of the image in-place: after a call to this function, the
758 image will have the given width and height.
760 Returns the (modified) image itself.
764 \helpref{Scale}{wximagescale}
766 \membersection{wxImage::Rotate}\label{wximagerotate}
768 \func{wxImage}{Rotate}{\param{double}{ angle}, \param{const wxPoint\& }{rotationCentre},
769 \param{bool}{ interpolating = true}, \param{wxPoint*}{ offsetAfterRotation = NULL}}
771 Rotates the image about the given point, by {\it angle} radians. Passing true
772 to {\it interpolating} results in better image quality, but is slower. If the
773 image has a mask, then the mask colour is used for the uncovered pixels in the
774 rotated image background. Else, black (rgb 0, 0, 0) will be used.
776 Returns the rotated image, leaving this image intact.
778 \membersection{wxImage::Rotate90}\label{wximagerotate90}
780 \constfunc{wxImage}{Rotate90}{\param{bool}{ clockwise = true}}
782 Returns a copy of the image rotated 90 degrees in the direction
783 indicated by {\it clockwise}.
785 \membersection{wxImage::SaveFile}\label{wximagesavefile}
787 \constfunc{bool}{SaveFile}{\param{const wxString\& }{name}, \param{int}{ type}}
789 \constfunc{bool}{SaveFile}{\param{const wxString\& }{name}, \param{const wxString\&}{ mimetype}}
791 Saves an image in the named file.
793 \constfunc{bool}{SaveFile}{\param{const wxString\& }{name}}
795 Saves an image in the named file. File type is determined from the extension of the
796 file name. Note that this function may fail if the extension is not recognized! You
797 can use one of the forms above to save images to files with non-standard extensions.
799 \constfunc{bool}{SaveFile}{\param{wxOutputStream\& }{stream}, \param{int}{ type}}
801 \constfunc{bool}{SaveFile}{\param{wxOutputStream\& }{stream}, \param{const wxString\&}{ mimetype}}
803 Saves an image in the given stream.
805 \wxheading{Parameters}
807 \docparam{name}{Name of the file to save the image to.}
809 \docparam{stream}{Opened output stream to save the image to.}
811 \docparam{type}{Currently these types can be used:
815 \twocolitem{{\bf wxBITMAP\_TYPE\_BMP}}{Save a BMP image file.}
816 \twocolitem{{\bf wxBITMAP\_TYPE\_JPEG}}{Save a JPEG image file.}
817 \twocolitem{{\bf wxBITMAP\_TYPE\_PNG}}{Save a PNG image file.}
818 \twocolitem{{\bf wxBITMAP\_TYPE\_PCX}}{Save a PCX image file (tries to save as 8-bit if possible, falls back to 24-bit otherwise).}
819 \twocolitem{{\bf wxBITMAP\_TYPE\_PNM}}{Save a PNM image file (as raw RGB always).}
820 \twocolitem{{\bf wxBITMAP\_TYPE\_TIFF}}{Save a TIFF image file.}
821 \twocolitem{{\bf wxBITMAP\_TYPE\_XPM}}{Save a XPM image file.}
822 \twocolitem{{\bf 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).}
823 \twocolitem{{\bf wxBITMAP\_TYPE\_CUR}}{Save a Windows cursor file (CUR).}
826 \docparam{mimetype}{MIME type.}
828 \wxheading{Return value}
830 true if the operation succeeded, false otherwise.
834 Depending on how wxWidgets has been configured, not all formats may be available.
836 Note: you can use \helpref{GetOptionInt}{wximagegetoptionint} to set the
837 hotspot before saving an image into a cursor file (default hotspot is in
838 the centre of the image):
840 image.SetOption(wxIMAGE_OPTION_CUR_HOTSPOT_X, hotspotX);
841 image.SetOption(wxIMAGE_OPTION_CUR_HOTSPOT_Y, hotspotY);
847 \helpref{wxImage::LoadFile}{wximageloadfile}
849 \pythonnote{In place of a single overloaded method name, wxPython
850 implements the following methods:\par
851 \indented{2cm}{\begin{twocollist}
852 \twocolitem{{\bf SaveFile(filename, type)}}{Saves the image using the given
853 type to the named file}
854 \twocolitem{{\bf SaveMimeFile(filename, mimetype)}}{Saves the image using the given
855 mimetype to the named file}
859 \perlnote{Methods supported by wxPerl are:\par
861 \item{bitmap->SaveFile( name, type )}
862 \item{bitmap->SaveFile( name, mimetype )}
866 \membersection{wxImage::Scale}\label{wximagescale}
868 \constfunc{wxImage}{Scale}{\param{int}{ width}, \param{int}{ height}}
870 Returns a scaled version of the image. This is also useful for
871 scaling bitmaps in general as the only other way to scale bitmaps
872 is to blit a wxMemoryDC into another wxMemoryDC.
874 It may be mentioned that the GTK port uses this function internally
875 to scale bitmaps when using mapping modes in wxDC.
880 // get the bitmap from somewhere
883 // rescale it to have size of 32*32
884 if ( bmp.GetWidth() != 32 || bmp.GetHeight() != 32 )
886 wxImage image = bmp.ConvertToImage();
887 bmp = wxBitmap(image.Scale(32, 32));
889 // another possibility:
890 image.Rescale(32, 32);
898 \helpref{Rescale}{wximagerescale}
900 \membersection{wxImage::SetAlpha}\label{wximagesetalpha}
902 \func{void}{SetAlpha}{\param{unsigned char *}{alpha = {\tt NULL}}}
904 This function is similar to \helpref{SetData}{wximagesetdata} and has similar
905 restrictions. The pointer passed to it may however be {\tt NULL} in which case
906 the function will allocate the alpha array internally -- this is useful to add
907 alpha channel data to an image which doesn't have any. If the pointer is not
908 {\tt NULL}, it must have one byte for each image pixel and be allocated with
909 {\tt malloc()}. wxImage takes ownership of the pointer and will free it.
911 \func{void}{SetAlpha}{\param{int }{x}, \param{int }{y}, \param{unsigned char }{alpha}}
913 Sets the alpha value for the given pixel. This function should only be called
914 if the image has alpha channel data, use \helpref{HasAlpha}{wximagehasalpha} to
917 \membersection{wxImage::SetData}\label{wximagesetdata}
919 \func{void}{SetData}{\param{unsigned char*}{data}}
921 Sets the image data without performing checks. The data given must have
922 the size (width*height*3) or results will be unexpected. Don't use this
923 method if you aren't sure you know what you are doing.
925 The data must have been allocated with {\tt malloc()}, {\large {\bf NOT}} with
928 After this call the pointer to the data is owned by the wxImage object,
929 that will be responsible for deleting it.
930 Do not pass to this function a pointer obtained through
931 \helpref{wxImage::GetData}{wximagegetdata}.
933 \membersection{wxImage::SetMask}\label{wximagesetmask}
935 \func{void}{SetMask}{\param{bool}{ hasMask = true}}
937 Specifies whether there is a mask or not. The area of the mask is determined by the current mask colour.
939 \membersection{wxImage::SetMaskColour}\label{wximagesetmaskcolour}
941 \func{void}{SetMaskColour}{\param{unsigned char }{red}, \param{unsigned char }{green}, \param{unsigned char }{blue}}
943 Sets the mask colour for this image (and tells the image to use the mask).
945 \membersection{wxImage::SetMaskFromImage}\label{wximagesetmaskfromimage}
947 \func{bool}{SetMaskFromImage}{\param{const wxImage\&}{ mask}, \param{unsigned char}{ mr}, \param{unsigned char}{ mg}, \param{unsigned char}{ mb}}
949 \wxheading{Parameters}
951 \docparam{mask}{The mask image to extract mask shape from. Must have same dimensions as the image.}
953 \docparam{mr,mg,mb}{RGB value of pixels in {\it mask} that will be used to create the mask.}
955 Sets image's mask so that the pixels that have RGB value of {\it mr,mg,mb}
956 in {\it mask} will be masked in the image. This is done by first finding an
957 unused colour in the image, setting this colour as the mask colour and then
958 using this colour to draw all pixels in the image who corresponding pixel
959 in {\it mask} has given RGB value.
961 \wxheading{Return value}
963 Returns false if {\it mask} does not have same dimensions as the image or if
964 there is no unused colour left. Returns true if the mask was successfully
969 Note that this method involves computing the histogram, which is
970 computationally intensive operation.
972 \membersection{wxImage::SetOption}\label{wximagesetoption}
974 \func{void}{SetOption}{\param{const wxString\&}{ name}, \param{const wxString\&}{ value}}
976 \func{void}{SetOption}{\param{const wxString\&}{ name}, \param{int}{ value}}
978 Sets a user-defined option. The function is case-insensitive to {\it name}.
980 For example, when saving as a JPEG file, the option {\bf quality} is
981 used, which is a number between 0 and 100 (0 is terrible, 100 is very good).
985 \helpref{wxImage::GetOption}{wximagegetoption},\rtfsp
986 \helpref{wxImage::GetOptionInt}{wximagegetoptionint},\rtfsp
987 \helpref{wxImage::HasOption}{wximagehasoption}
989 \membersection{wxImage::SetPalette}\label{wximagesetpalette}
991 \func{void}{SetPalette}{\param{const wxPalette\&}{ palette}}
993 Associates a palette with the image. The palette may be used when converting
994 wxImage to wxBitmap (MSW only at present) or in file save operations (none as yet).
996 \membersection{wxImage::SetRGB}\label{wximagesetrgb}
998 \func{void}{SetRGB}{\param{int }{x}, \param{int }{y}, \param{unsigned char }{red}, \param{unsigned char }{green}, \param{unsigned char }{blue}}
1000 Sets the pixel at the given coordinate. This routine performs bounds-checks
1001 for the coordinate so it can be considered a safe way to manipulate the
1002 data, but in some cases this might be too slow so that the data will have to
1003 be set directly. In that case you will have to get access to the image data
1004 using the \helpref{GetData}{wximagegetdata} method.
1006 \membersection{wxImage::operator $=$}
1008 \func{wxImage\& }{operator $=$}{\param{const wxImage\& }{image}}
1010 Assignment operator. This operator does not copy any data, but instead
1011 passes a pointer to the data in {\it image} and increments a reference
1012 counter. It is a fast operation.
1014 \wxheading{Parameters}
1016 \docparam{image}{Image to assign.}
1018 \wxheading{Return value}
1020 Returns 'this' object.
1022 \membersection{wxImage::operator $==$}
1024 \constfunc{bool}{operator $==$}{\param{const wxImage\& }{image}}
1026 Equality operator. This operator tests whether the internal data pointers are
1027 equal (a fast test).
1029 \wxheading{Parameters}
1031 \docparam{image}{Image to compare with 'this'}
1033 \wxheading{Return value}
1035 Returns true if the images were effectively equal, false otherwise.
1037 \membersection{wxImage::operator $!=$}
1039 \constfunc{bool}{operator $!=$}{\param{const wxImage\& }{image}}
1041 Inequality operator. This operator tests whether the internal data pointers are
1042 unequal (a fast test).
1044 \wxheading{Parameters}
1046 \docparam{image}{Image to compare with 'this'}
1048 \wxheading{Return value}
1050 Returns true if the images were unequal, false otherwise.
1052 \section{\class{wxImageHandler}}\label{wximagehandler}
1054 This is the base class for implementing image file loading/saving, and image creation from data.
1055 It is used within wxImage and is not normally seen by the application.
1057 If you wish to extend the capabilities of wxImage, derive a class from wxImageHandler
1058 and add the handler using \helpref{wxImage::AddHandler}{wximageaddhandler} in your
1059 application initialisation.
1061 \wxheading{Note (Legal Issue)}
1063 This software is based in part on the work of the Independent JPEG Group.
1065 (Applies when wxWidgets is linked with JPEG support. wxJPEGHandler uses libjpeg
1068 \wxheading{Derived from}
1070 \helpref{wxObject}{wxobject}
1072 \wxheading{Include files}
1076 \wxheading{See also}
1078 \helpref{wxImage}{wximage},
1079 \helpref{wxInitAllImageHandlers}{wxinitallimagehandlers}
1081 \latexignore{\rtfignore{\wxheading{Members}}}
1083 \membersection{wxImageHandler::wxImageHandler}\label{wximagehandlerconstr}
1085 \func{}{wxImageHandler}{\void}
1087 Default constructor. In your own default constructor, initialise the members
1088 m\_name, m\_extension and m\_type.
1090 \membersection{wxImageHandler::\destruct{wxImageHandler}}
1092 \func{}{\destruct{wxImageHandler}}{\void}
1094 Destroys the wxImageHandler object.
1096 \membersection{wxImageHandler::GetName}
1098 \constfunc{wxString}{GetName}{\void}
1100 Gets the name of this handler.
1102 \membersection{wxImageHandler::GetExtension}
1104 \constfunc{wxString}{GetExtension}{\void}
1106 Gets the file extension associated with this handler.
1108 \membersection{wxImageHandler::GetImageCount}\label{wximagehandlergetimagecount}
1110 \func{int}{GetImageCount}{\param{wxInputStream\&}{ stream}}
1112 If the image file contains more than one image and the image handler is capable
1113 of retrieving these individually, this function will return the number of
1116 \docparam{stream}{Opened input stream for reading image data. Currently, the stream must support seeking.}
1118 \wxheading{Return value}
1120 Number of available images. For most image handlers, this is 1 (exceptions
1121 are TIFF and ICO formats).
1123 \membersection{wxImageHandler::GetType}
1125 \constfunc{long}{GetType}{\void}
1127 Gets the image type associated with this handler.
1129 \membersection{wxImageHandler::GetMimeType}
1131 \constfunc{wxString}{GetMimeType}{\void}
1133 Gets the MIME type associated with this handler.
1135 \membersection{wxImageHandler::LoadFile}\label{wximagehandlerloadfile}
1137 \func{bool}{LoadFile}{\param{wxImage* }{image}, \param{wxInputStream\&}{ stream}, \param{bool}{ verbose=true}, \param{int}{ index=0}}
1139 Loads a image from a stream, putting the resulting data into {\it image}. If the image file contains
1140 more than one image and the image handler is capable of retrieving these individually, {\it index}
1141 indicates which image to read from the stream.
1143 \wxheading{Parameters}
1145 \docparam{image}{The image object which is to be affected by this operation.}
1147 \docparam{stream}{Opened input stream for reading image data.}
1149 \docparam{verbose}{If set to true, errors reported by the image handler will produce wxLogMessages.}
1151 \docparam{index}{The index of the image in the file (starting from zero).}
1153 \wxheading{Return value}
1155 true if the operation succeeded, false otherwise.
1157 \wxheading{See also}
1159 \helpref{wxImage::LoadFile}{wximageloadfile},
1160 \helpref{wxImage::SaveFile}{wximagesavefile},
1161 \helpref{wxImageHandler::SaveFile}{wximagehandlersavefile}
1163 \membersection{wxImageHandler::SaveFile}\label{wximagehandlersavefile}
1165 \func{bool}{SaveFile}{\param{wxImage* }{image}, \param{wxOutputStream\& }{stream}}
1167 Saves a image in the output stream.
1169 \wxheading{Parameters}
1171 \docparam{image}{The image object which is to be affected by this operation.}
1173 \docparam{stream}{Opened output stream for writing the data.}
1175 \wxheading{Return value}
1177 true if the operation succeeded, false otherwise.
1179 \wxheading{See also}
1181 \helpref{wxImage::LoadFile}{wximageloadfile},
1182 \helpref{wxImage::SaveFile}{wximagesavefile},
1183 \helpref{wxImageHandler::LoadFile}{wximagehandlerloadfile}
1185 \membersection{wxImageHandler::SetName}
1187 \func{void}{SetName}{\param{const wxString\& }{name}}
1189 Sets the handler name.
1191 \wxheading{Parameters}
1193 \docparam{name}{Handler name.}
1195 \membersection{wxImageHandler::SetExtension}
1197 \func{void}{SetExtension}{\param{const wxString\& }{extension}}
1199 Sets the handler extension.
1201 \wxheading{Parameters}
1203 \docparam{extension}{Handler extension.}
1205 \membersection{wxImageHandler::SetMimeType}\label{wximagehandlersetmimetype}
1207 \func{void}{SetMimeType}{\param{const wxString\& }{mimetype}}
1209 Sets the handler MIME type.
1211 \wxheading{Parameters}
1213 \docparam{mimename}{Handler MIME type.}
1215 \membersection{wxImageHandler::SetType}
1217 \func{void}{SetType}{\param{long }{type}}
1219 Sets the handler type.
1221 \wxheading{Parameters}
1223 \docparam{name}{Handler type.}