]> git.saurik.com Git - wxWidgets.git/blame - docs/latex/wx/image.tex
corrected ancient event type constant in an example
[wxWidgets.git] / docs / latex / wx / image.tex
CommitLineData
ce045aed
WS
1%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2%% Name: image.tex
3%% Purpose: wxImage documentation
4%% Author: wxWidgets Team
5%% Modified by:
6%% Created:
7%% RCS-ID: $Id$
8%% Copyright: (c) wxWidgets Team
9%% License: wxWindows license
10%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
11
1e6d9499
JS
12\section{\class{wxImage}}\label{wximage}
13
14This class encapsulates a platform-independent image. An image can be created
b06a6b20 15from data, or using \helpref{wxBitmap::ConvertToImage}{wxbitmapconverttoimage}. An image
1e6d9499
JS
16can be loaded from a file in a variety of formats, and is extensible to new formats
17via image format handlers. Functions are available to set and get image bits, so
18it can be used for basic image manipulation.
19
ce045aed 20A wxImage cannot (currently) be drawn directly to a \helpref{wxDC}{wxdc}. Instead,
7468b994 21a platform-specific \helpref{wxBitmap}{wxbitmap} object must be created from it using
ce045aed 22the \helpref{wxBitmap::wxBitmap(wxImage,int depth)}{wxbitmapctor} constructor.
b06a6b20 23This bitmap can then
7468b994
RR
24be drawn in a device context, using \helpref{wxDC::DrawBitmap}{wxdcdrawbitmap}.
25
26One colour value of the image may be used as a mask colour which will lead to the automatic
27creation of a \helpref{wxMask}{wxmask} object associated to the bitmap object.
12a44087 28
487659e0
VZ
29\wxheading{Alpha channel support}
30
fc2171bd 31Starting from wxWidgets 2.5.0 wxImage supports alpha channel data, that is in
487659e0 32addition to a byte for the red, green and blue colour components for each pixel
e0cb07e3
DS
33it also stores a byte representing the pixel opacity. An alpha value of $0$
34corresponds to a transparent pixel (null opacity) while a value of $255$
487659e0
VZ
35means that the pixel is 100\% opaque.
36
ce045aed 37Unlike RGB data, not all images have an alpha channel and before using
487659e0 38\helpref{GetAlpha}{wximagegetalpha} you should check if this image contains
e0cb07e3
DS
39an alpha channel with \helpref{HasAlpha}{wximagehasalpha}. Note that currently only
40images loaded from PNG files with transparency information will have an alpha
41channel but alpha support will be added to the other formats as well (as well
42as support for saving images with alpha channel which also isn't implemented).
487659e0 43
8727a1fe
GRG
44\wxheading{Available image handlers}
45
46The following image handlers are available. {\bf wxBMPHandler} is always
2edb0bde 47installed by default. To use other image formats, install the appropriate
ce045aed 48handler with \helpref{wxImage::AddHandler}{wximageaddhandler} or
8727a1fe
GRG
49\helpref{wxInitAllImageHandlers}{wxinitallimagehandlers}.
50
51\twocolwidtha{5cm}%
52\begin{twocollist}
4fa0a5b4 53\twocolitem{\indexit{wxBMPHandler}}{For loading and saving, always installed.}
487659e0 54\twocolitem{\indexit{wxPNGHandler}}{For loading (including alpha support) and saving.}
606a3178
GT
55\twocolitem{\indexit{wxJPEGHandler}}{For loading and saving.}
56\twocolitem{\indexit{wxGIFHandler}}{Only for loading, due to legal issues.}
57\twocolitem{\indexit{wxPCXHandler}}{For loading and saving (see below).}
58\twocolitem{\indexit{wxPNMHandler}}{For loading and saving (see below).}
b86e511a 59\twocolitem{\indexit{wxTIFFHandler}}{For loading and saving.}
4fa0a5b4 60\twocolitem{\indexit{wxIFFHandler}}{For loading only.}
b86e511a 61\twocolitem{\indexit{wxXPMHandler}}{For loading and saving.}
37b83ca6 62\twocolitem{\indexit{wxICOHandler}}{For loading and saving.}
a61d25e6 63\twocolitem{\indexit{wxCURHandler}}{For loading and saving.}
4fa0a5b4 64\twocolitem{\indexit{wxANIHandler}}{For loading only.}
8727a1fe
GRG
65\end{twocollist}
66
67When saving in PCX format, {\bf wxPCXHandler} will count the number of
68different colours in the image; if there are 256 or less colours, it will
69save as 8 bit, else it will save as 24 bit.
70
71Loading PNMs only works for ASCII or raw RGB images. When saving in
72PNM format, {\bf wxPNMHandler} will always save as raw RGB.
73
1e6d9499
JS
74\wxheading{Derived from}
75
76\helpref{wxObject}{wxobject}
77
954b8ae6
JS
78\wxheading{Include files}
79
80<wx/image.h>
81
1e6d9499
JS
82\wxheading{See also}
83
ce045aed 84\helpref{wxBitmap}{wxbitmap},
b5a4a47d 85\helpref{wxInitAllImageHandlers}{wxinitallimagehandlers}
1e6d9499
JS
86
87\latexignore{\rtfignore{\wxheading{Members}}}
88
07d0abae 89
f0e8a2d0 90\membersection{wxImage::wxImage}\label{wximagector}
1e6d9499
JS
91
92\func{}{wxImage}{\void}
93
94Default constructor.
95
96\func{}{wxImage}{\param{const wxImage\& }{image}}
97
98Copy constructor.
99
100\func{}{wxImage}{\param{const wxBitmap\&}{ bitmap}}
101
b06a6b20
VS
102(Deprecated form, use \helpref{wxBitmap::ConvertToImage}{wxbitmapconverttoimage}
103instead.) Constructs an image from a platform-dependent bitmap. This preserves
12a44087
RR
104mask information so that bitmaps and images can be converted back
105and forth without loss in that respect.
1e6d9499 106
ff865c13 107\func{}{wxImage}{\param{int}{ width}, \param{int}{ height}, \param{bool}{ clear=true}}
1e6d9499 108
ff865c13
JS
109Creates an image with the given width and height. If {\it clear} is true, the new image will be initialized to black.
110Otherwise, the image data will be uninitialized.
1e6d9499 111
60b1fda2 112\func{}{wxImage}{\param{int}{ width}, \param{int}{ height}, \param{unsigned char*}{ data}, \param{bool}{ static\_data = \false}}
f6bcfd97 113
ce045aed 114Creates an image from given data with the given width and height. If
cc81d32f 115{\it static\_data} is true, then wxImage will not delete the actual
f6bcfd97
BP
116image data in its destructor, otherwise it will free it by calling
117{\it free()}.
118
a61d25e6 119\func{}{wxImage}{\param{const wxString\& }{name}, \param{long}{ type = wxBITMAP\_TYPE\_ANY}, \param{int}{ index = -1}}
1e6d9499 120
a61d25e6 121\func{}{wxImage}{\param{const wxString\& }{name}, \param{const wxString\&}{ mimetype}, \param{int}{ index = -1}}
9e9ee68e 122
1e6d9499
JS
123Loads an image from a file.
124
a61d25e6 125\func{}{wxImage}{\param{wxInputStream\& }{stream}, \param{long}{ type = wxBITMAP\_TYPE\_ANY}, \param{int}{ index = -1}}
45b5751f 126
a61d25e6 127\func{}{wxImage}{\param{wxInputStream\& }{stream}, \param{const wxString\&}{ mimetype}, \param{int}{ index = -1}}
9e9ee68e 128
45b5751f
JS
129Loads an image from an input stream.
130
7ab37822
JS
131\func{}{wxImage}{\param{const char** }{xpmData}}
132
133Creates an image from XPM data.
134
1e6d9499
JS
135\wxheading{Parameters}
136
137\docparam{width}{Specifies the width of the image.}
138
139\docparam{height}{Specifies the height of the image.}
140
31fd9b6b 141\docparam{name}{Name of the file from which to load the image.}
1e6d9499 142
31fd9b6b 143\docparam{stream}{Opened input stream from which to load the image. Currently, the stream must support seeking.}
45b5751f 144
1e6d9499
JS
145\docparam{type}{May be one of the following:
146
6be663cf 147\twocolwidtha{5cm}%
1e6d9499 148\begin{twocollist}
606a3178
GT
149\twocolitem{\indexit{wxBITMAP\_TYPE\_BMP}}{Load a Windows bitmap file.}
150\twocolitem{\indexit{wxBITMAP\_TYPE\_GIF}}{Load a GIF bitmap file.}
151\twocolitem{\indexit{wxBITMAP\_TYPE\_JPEG}}{Load a JPEG bitmap file.}
152\twocolitem{\indexit{wxBITMAP\_TYPE\_PNG}}{Load a PNG bitmap file.}
153\twocolitem{\indexit{wxBITMAP\_TYPE\_PCX}}{Load a PCX bitmap file.}
154\twocolitem{\indexit{wxBITMAP\_TYPE\_PNM}}{Load a PNM bitmap file.}
155\twocolitem{\indexit{wxBITMAP\_TYPE\_TIF}}{Load a TIFF bitmap file.}
b86e511a 156\twocolitem{\indexit{wxBITMAP\_TYPE\_XPM}}{Load a XPM bitmap file.}
a61d25e6
VS
157\twocolitem{\indexit{wxBITMAP\_TYPE\_ICO}}{Load a Windows icon file (ICO).}
158\twocolitem{\indexit{wxBITMAP\_TYPE\_CUR}}{Load a Windows cursor file (CUR).}
658974ae 159\twocolitem{\indexit{wxBITMAP\_TYPE\_ANI}}{Load a Windows animated cursor file (ANI).}
606a3178 160\twocolitem{\indexit{wxBITMAP\_TYPE\_ANY}}{Will try to autodetect the format.}
31fd9b6b 161\end{twocollist}}
1e6d9499 162
9e9ee68e
VS
163\docparam{mimetype}{MIME type string (for example 'image/jpeg')}
164
a61d25e6 165\docparam{index}{Index of the image to load in the case that the image file contains multiple images.
ce045aed
WS
166This is only used by GIF, ICO and TIFF handlers. The default value (-1) means
167"choose the default image" and is interpreted as the first image (index=0) by
b931f7ee 168the GIF and TIFF handler and as the largest and most colourful one by the ICO handler.}
a61d25e6 169
7ab37822
JS
170\docparam{xpmData}{A pointer to XPM image data.}
171
31fd9b6b
GRG
172\wxheading{Remarks}
173
fc2171bd 174Depending on how wxWidgets has been configured, not all formats may be available.
31fd9b6b 175
fa482912 176Note: any handler other than BMP must be previously
ce045aed 177initialized with \helpref{wxImage::AddHandler}{wximageaddhandler} or
31fd9b6b 178\helpref{wxInitAllImageHandlers}{wxinitallimagehandlers}.
0a9f2522 179
ce045aed 180Note: you can use \helpref{GetOptionInt}{wximagegetoptionint} to get the
a61d25e6
VS
181hotspot for loaded cursor file:
182\begin{verbatim}
fd94e8aa
VS
183 int hotspot_x = image.GetOptionInt(wxIMAGE_OPTION_CUR_HOTSPOT_X);
184 int hotspot_y = image.GetOptionInt(wxIMAGE_OPTION_CUR_HOTSPOT_Y);
a61d25e6
VS
185
186\end{verbatim}
187
1e6d9499
JS
188\wxheading{See also}
189
190\helpref{wxImage::LoadFile}{wximageloadfile}
191
f899db6d
RD
192\pythonnote{Constructors supported by wxPython are:\par
193\indented{2cm}{\begin{twocollist}
c9110876
VS
194\twocolitem{{\bf wxImage(name, flag)}}{Loads an image from a file}
195\twocolitem{{\bf wxNullImage()}}{Create a null image (has no size or
f899db6d 196image data)}
c9110876 197\twocolitem{{\bf wxEmptyImage(width, height)}}{Creates an empty image
f899db6d 198of the given size}
c9110876 199\twocolitem{{\bf wxImageFromMime(name, mimetype}}{Creates an image from
f899db6d 200the given file of the given mimetype}
c9110876 201\twocolitem{{\bf wxImageFromBitmap(bitmap)}}{Creates an image from a
f899db6d
RD
202platform-dependent bitmap}
203\end{twocollist}}
204}
205
5873607e
VZ
206\perlnote{Constructors supported by wxPerl are:\par
207\begin{itemize}
208\item{Wx::Image->new( bitmap )}
25e4b4bf 209\item{Wx::Image->new( icon )}
5873607e 210\item{Wx::Image->new( width, height )}
25e4b4bf
MB
211\item{Wx::Image->new( width, height, data )}
212\item{Wx::Image->new( file, type, index )}
213\item{Wx::Image->new( file, mimetype, index )}
214\item{Wx::Image->new( stream, type, index )}
215\item{Wx::Image->new( stream, mimetype, index )}
5873607e
VZ
216\end{itemize}
217}
218
07d0abae 219
f0e8a2d0 220\membersection{wxImage::\destruct{wxImage}}\label{wximagedtor}
1e6d9499
JS
221
222\func{}{\destruct{wxImage}}{\void}
223
224Destructor.
225
07d0abae 226
1e6d9499
JS
227\membersection{wxImage::AddHandler}\label{wximageaddhandler}
228
229\func{static void}{AddHandler}{\param{wxImageHandler*}{ handler}}
230
231Adds a handler to the end of the static list of format handlers.
232
233\docparam{handler}{A new image format handler object. There is usually only one instance
234of a given handler class in an application session.}
235
236\wxheading{See also}
237
238\helpref{wxImageHandler}{wximagehandler}
239
4fa0a5b4
VS
240\func{bool}{CanRead}{\param{const wxString\&}{ filename}}
241
cc81d32f 242returns true if the current image handlers can read this file
4fa0a5b4 243
e7240349 244\pythonnote{In wxPython this static method is named {\tt wxImage\_AddHandler}.}
07d0abae 245
f0e8a2d0 246\membersection{wxImage::CleanUpHandlers}\label{wximagecleanuphandlers}
1e6d9499
JS
247
248\func{static void}{CleanUpHandlers}{\void}
249
250Deletes all image handlers.
251
fc2171bd 252This function is called by wxWidgets on exit.
1e6d9499 253
07d0abae 254
d7af2fea
VS
255\membersection{wxImage::ComputeHistogram}\label{wximagecomputehistogram}
256
257\constfunc{unsigned long}{ComputeHistogram}{\param{wxImageHistogram\& }{histogram}}
258
ce045aed
WS
259Computes the histogram of the image. {\it histogram} is a reference to
260wxImageHistogram object. wxImageHistogram is a specialization of
d7af2fea
VS
261\helpref{wxHashMap}{wxhashmap} "template" and is defined as follows:
262
263\begin{verbatim}
264class WXDLLEXPORT wxImageHistogramEntry
265{
266public:
267 wxImageHistogramEntry() : index(0), value(0) {}
268 unsigned long index;
269 unsigned long value;
270};
271
272WX_DECLARE_EXPORTED_HASH_MAP(unsigned long, wxImageHistogramEntry,
273 wxIntegerHash, wxIntegerEqual,
274 wxImageHistogram);
275\end{verbatim}
276
277\wxheading{Return value}
278
279Returns number of colours in the histogram.
280
07d0abae 281
ff5ad794
VS
282\membersection{wxImage::ConvertAlphaToMask}\label{wximageconvertalphatomask}
283
21dc4be5 284\func{bool}{ConvertAlphaToMask}{\param{unsigned char}{ threshold = $128$}}
ff5ad794
VS
285
286If the image has alpha channel, this method converts it to mask. All pixels
287with alpha value less than \arg{threshold} are replaced with mask colour
288and the alpha channel is removed. Mask colour is chosen automatically using
289\helpref{FindFirstUnusedColour}{wximagefindfirstunusedcolour}.
290
291If the image image doesn't have alpha channel,
292ConvertAlphaToMask does nothing.
293
294\wxheading{Return value}
295
ce045aed 296\false if FindFirstUnusedColour returns \false, \true otherwise.
ff5ad794 297
07d0abae 298
1e6d9499
JS
299\membersection{wxImage::ConvertToBitmap}\label{wximageconverttobitmap}
300
301\constfunc{wxBitmap}{ConvertToBitmap}{\void}
302
f510b7b2 303Deprecated, use equivalent \helpref{wxBitmap constructor}{wxbitmapctor}
b06a6b20 304(which takes wxImage and depth as its arguments) instead.
7468b994 305
07d0abae 306
ec85956a
JS
307\membersection{wxImage::ConvertToGreyscale}\label{wximageconverttogreyscale}
308
309\constfunc{wxImage}{ConvertToGreyscale}{\param{double}{ lr = 0.299}, \param{double}{ lg = 0.587}, \param{double}{ lb = 0.114}}
310
311Returns a greyscale version of the image. The returned image uses the luminance
312component of the original to calculate the greyscale. Defaults to using
313ITU-T BT.601 when converting to YUV, where every pixel equals
314(R * {\it lr}) + (G * {\it lg}) + (B * {\it lb}).
315
316
b06a6b20 317\membersection{wxImage::ConvertToMono}\label{wxbitmapconverttomono}
1e6d9499 318
b06a6b20
VS
319\constfunc{wxImage}{ConvertToMono}{\param{unsigned char}{ r}, \param{unsigned char}{ g}, \param{unsigned char}{ b}}
320
321Returns monochromatic version of the image. The returned image has white
ce045aed 322colour where the original has {\it (r,g,b)} colour and black colour
b06a6b20 323everywhere else.
3ca6a5f0 324
07d0abae 325
f6bcfd97
BP
326\membersection{wxImage::Copy}\label{wximagecopy}
327
328\constfunc{wxImage}{Copy}{\void}
329
330Returns an identical copy of the image.
331
07d0abae 332
1e6d9499
JS
333\membersection{wxImage::Create}\label{wximagecreate}
334
ff865c13 335\func{bool}{Create}{\param{int}{ width}, \param{int}{ height}, \param{bool}{ clear=true}}
1e6d9499 336
ff865c13
JS
337Creates a fresh image. If {\it clear} is true, the new image will be initialized to black.
338Otherwise, the image data will be uninitialized.
1e6d9499
JS
339
340\wxheading{Parameters}
341
342\docparam{width}{The width of the image in pixels.}
343
344\docparam{height}{The height of the image in pixels.}
345
346\wxheading{Return value}
347
cc81d32f 348true if the call succeeded, false otherwise.
1e6d9499 349
07d0abae 350
1e6d9499
JS
351\membersection{wxImage::Destroy}\label{wximagedestroy}
352
f6e9a818 353\func{void}{Destroy}{\void}
1e6d9499
JS
354
355Destroys the image data.
356
07d0abae 357
37b83ca6
VS
358\membersection{wxImage::FindFirstUnusedColour}\label{wximagefindfirstunusedcolour}
359
360\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}}
361
362\wxheading{Parameters}
363
364\docparam{r,g,b}{Pointers to variables to save the colour.}
365
366\docparam{startR,startG,startB}{Initial values of the colour. Returned colour
367will have RGB values equal to or greater than these.}
368
369Finds the first colour that is never used in the image. The search begins at
370given initial colour and continues by increasing R, G and B components (in this
371order) by 1 until an unused colour is found or the colour space exhausted.
372
373\wxheading{Return value}
374
cc81d32f 375Returns false if there is no unused colour left, true on success.
37b83ca6
VS
376
377\wxheading{Notes}
378
379Note that this method involves computing the histogram, which is
380computationally intensive operation.
381
07d0abae 382
f0e8a2d0 383\membersection{wxImage::FindHandler}\label{wximagefindhandler}
1e6d9499
JS
384
385\func{static wxImageHandler*}{FindHandler}{\param{const wxString\& }{name}}
386
387Finds the handler with the given name.
388
389\func{static wxImageHandler*}{FindHandler}{\param{const wxString\& }{extension}, \param{long}{ imageType}}
390
391Finds the handler associated with the given extension and type.
392
393\func{static wxImageHandler*}{FindHandler}{\param{long }{imageType}}
394
395Finds the handler associated with the given image type.
396
9e9ee68e
VS
397\func{static wxImageHandler*}{FindHandlerMime}{\param{const wxString\& }{mimetype}}
398
399Finds the handler associated with the given MIME type.
400
1e6d9499
JS
401\docparam{name}{The handler name.}
402
403\docparam{extension}{The file extension, such as ``bmp".}
404
f6fcbb63 405\docparam{imageType}{The image type, such as wxBITMAP\_TYPE\_BMP.}
1e6d9499 406
9e9ee68e
VS
407\docparam{mimetype}{MIME type.}
408
1e6d9499
JS
409\wxheading{Return value}
410
411A pointer to the handler if found, NULL otherwise.
412
413\wxheading{See also}
414
415\helpref{wxImageHandler}{wximagehandler}
416
07d0abae 417
f0e8a2d0 418\membersection{wxImage::GetImageExtWildcard}\label{wximagegetimageextwildcard}
939fadc8
JS
419
420\func{static wxString}{GetImageExtWildcard}{\void}
421
422Iterates all registered wxImageHandler objects, and returns a string containing file extension masks
423suitable for passing to file open/save dialog boxes.
424
425\wxheading{Return value}
426
427The format of the returned string is "(*.ext1;*.ext2)|*.ext1;*.ext2".
428
429It is usually a good idea to prepend a description before passing the result to the dialog.
430
431Example:
432
433\begin{verbatim}
ce045aed 434 wxFileDialog FileDlg( this, "Choose Image", ::wxGetCwd(), "", _("Image Files ") + wxImage::GetImageExtWildcard(), wxOPEN );
939fadc8
JS
435\end{verbatim}
436
437\wxheading{See also}
438
439\helpref{wxImageHandler}{wximagehandler}
440
07d0abae 441
487659e0
VZ
442\membersection{wxImage::GetAlpha}\label{wximagegetalpha}
443
444\constfunc{unsigned char}{GetAlpha}{\param{int}{ x}, \param{int}{ y}}
445
446Returns the alpha value for the given pixel. This function may only be called
447for the images with alpha channel, use \helpref{HasAlpha}{wximagehasalpha} to
448check for this.
449
450The returned value is the {\it opacity} of the image, i.e. the value of $0$
451corresponds to the transparent pixels while the value of $255$ -- to the opaque
452ones.
453
454\constfunc{unsigned char *}{GetAlpha}{\void}
455
456Returns pointer to the array storing the alpha values for this image. This
457pointer is {\tt NULL} for the images without the alpha channel. If the image
458does have it, this pointer may be used to directly manipulate the alpha values
459which are stored as the \helpref{RGB}{wximagegetdata} ones.
460
07d0abae 461
1e6d9499
JS
462\membersection{wxImage::GetBlue}\label{wximagegetblue}
463
464\constfunc{unsigned char}{GetBlue}{\param{int}{ x}, \param{int}{ y}}
465
466Returns the blue intensity at the given coordinate.
467
07d0abae 468
1e6d9499
JS
469\membersection{wxImage::GetData}\label{wximagegetdata}
470
471\constfunc{unsigned char*}{GetData}{\void}
472
12a44087
RR
473Returns the image data as an array. This is most often used when doing
474direct image manipulation. The return value points to an array of
487659e0 475characters in RGBRGBRGB$\ldots$ format in the top-to-bottom, left-to-right
6028be3f
VZ
476order, that is the first RGB triplet corresponds to the pixel first pixel of
477the first row, the second one --- to the second pixel of the first row and so
478on until the end of the first row, with second row following after it and so
479on.
1e6d9499 480
f811bc9a
MB
481You should not delete the returned pointer nor pass it to
482\helpref{wxImage::SetData}{wximagesetdata}.
483
07d0abae 484
1e6d9499
JS
485\membersection{wxImage::GetGreen}\label{wximagegetgreen}
486
487\constfunc{unsigned char}{GetGreen}{\param{int}{ x}, \param{int}{ y}}
488
489Returns the green intensity at the given coordinate.
490
07d0abae 491
649d13e8 492\membersection{wxImage::GetImageCount}\label{wximagegetimagecount}
a61d25e6 493
649d13e8 494\func{static int}{GetImageCount}{\param{const wxString\&}{ filename}, \param{long}{ type = wxBITMAP\_TYPE\_ANY}}
a61d25e6 495
649d13e8 496\func{static int}{GetImageCount}{\param{wxInputStream\&}{ stream}, \param{long}{ type = wxBITMAP\_TYPE\_ANY}}
a61d25e6 497
ce045aed 498If the image file contains more than one image and the image handler is capable
a61d25e6
VS
499of retrieving these individually, this function will return the number of
500available images.
501
502\docparam{name}{Name of the file to query.}
503
504\docparam{stream}{Opened input stream with image data. Currently, the stream must support seeking.}
505
506\docparam{type}{May be one of the following:
507
508\twocolwidtha{5cm}%
509\begin{twocollist}
510\twocolitem{\indexit{wxBITMAP\_TYPE\_BMP}}{Load a Windows bitmap file.}
511\twocolitem{\indexit{wxBITMAP\_TYPE\_GIF}}{Load a GIF bitmap file.}
512\twocolitem{\indexit{wxBITMAP\_TYPE\_JPEG}}{Load a JPEG bitmap file.}
513\twocolitem{\indexit{wxBITMAP\_TYPE\_PNG}}{Load a PNG bitmap file.}
514\twocolitem{\indexit{wxBITMAP\_TYPE\_PCX}}{Load a PCX bitmap file.}
515\twocolitem{\indexit{wxBITMAP\_TYPE\_PNM}}{Load a PNM bitmap file.}
516\twocolitem{\indexit{wxBITMAP\_TYPE\_TIF}}{Load a TIFF bitmap file.}
517\twocolitem{\indexit{wxBITMAP\_TYPE\_XPM}}{Load a XPM bitmap file.}
518\twocolitem{\indexit{wxBITMAP\_TYPE\_ICO}}{Load a Windows icon file (ICO).}
519\twocolitem{\indexit{wxBITMAP\_TYPE\_CUR}}{Load a Windows cursor file (CUR).}
658974ae 520\twocolitem{\indexit{wxBITMAP\_TYPE\_ANI}}{Load a Windows animated cursor file (ANI).}
a61d25e6
VS
521\twocolitem{\indexit{wxBITMAP\_TYPE\_ANY}}{Will try to autodetect the format.}
522\end{twocollist}}
523
524\wxheading{Return value}
525
526Number of available images. For most image handlers, this is 1 (exceptions
527are TIFF and ICO formats).
528
07d0abae 529
f0e8a2d0 530\membersection{wxImage::GetHandlers}\label{wximagegethandlers}
1e6d9499
JS
531
532\func{static wxList\&}{GetHandlers}{\void}
533
534Returns the static list of image format handlers.
535
536\wxheading{See also}
537
538\helpref{wxImageHandler}{wximagehandler}
539
07d0abae 540
1e6d9499
JS
541\membersection{wxImage::GetHeight}\label{wximagegetheight}
542
543\constfunc{int}{GetHeight}{\void}
544
545Gets the height of the image in pixels.
546
07d0abae 547
1e6d9499
JS
548\membersection{wxImage::GetMaskBlue}\label{wximagegetmaskblue}
549
550\constfunc{unsigned char}{GetMaskBlue}{\void}
551
552Gets the blue value of the mask colour.
553
07d0abae 554
1e6d9499
JS
555\membersection{wxImage::GetMaskGreen}\label{wximagegetmaskgreen}
556
557\constfunc{unsigned char}{GetMaskGreen}{\void}
558
559Gets the green value of the mask colour.
560
07d0abae 561
1e6d9499
JS
562\membersection{wxImage::GetMaskRed}\label{wximagegetmaskred}
563
564\constfunc{unsigned char}{GetMaskRed}{\void}
565
566Gets the red value of the mask colour.
567
07d0abae 568
b737ad10
RR
569\membersection{wxImage::GetOrFindMaskColour}\label{wximagegetgetorsetmaskcolour}
570
571\constfunc{bool}{GetOrFindMaskColour}{\param{unsigned char}{ *r}, \param{unsigned char}{ *g}, \param{unsigned char}{ *b}}
572
ce045aed 573Get the current mask colour or find a suitable unused colour that could be
b737ad10
RR
574used as a mask colour. Returns {\tt true} if the image currently has a mask.
575
576
3ca6a5f0
BP
577\membersection{wxImage::GetPalette}\label{wximagegetpalette}
578
579\constfunc{const wxPalette\&}{GetPalette}{\void}
580
581Returns the palette associated with the image. Currently the palette is only
b06a6b20 582used when converting to wxBitmap under Windows.
3ca6a5f0
BP
583
584Eventually wxImage handlers will set the palette if one exists in the image file.
585
07d0abae 586
7b4c3149
VZ
587\membersection{wxImage::GetRed}\label{wximagegetred}
588
589\constfunc{unsigned char}{GetRed}{\param{int}{ x}, \param{int}{ y}}
590
591Returns the red intensity at the given coordinate.
592
07d0abae 593
fc9c7c09
RR
594\membersection{wxImage::GetSubImage}\label{wximagegetsubimage}
595
7468b994 596\constfunc{wxImage}{GetSubImage}{\param{const wxRect\&}{ rect}}
fc9c7c09 597
ce045aed 598Returns a sub image of the current one as long as the rect belongs entirely to
fc9c7c09
RR
599the image.
600
07d0abae 601
1e6d9499
JS
602\membersection{wxImage::GetWidth}\label{wximagegetwidth}
603
604\constfunc{int}{GetWidth}{\void}
605
606Gets the width of the image in pixels.
607
608\wxheading{See also}
609
610\helpref{wxImage::GetHeight}{wximagegetheight}
611
07d0abae 612
978d3d36
VZ
613\membersection{HSVValue::HSVValue}\label{hsvvaluehsvvalue}
614
615\func{}{HSVValue}{\param{double }{h = 0.0}, \param{double }{s = 0.0}, \param{double }{v = 0.0}}
616
617Constructor for HSVValue, an object that contains values for hue, saturation and value which
618represent the value of a color. It is used by \helpref{wxImage::HSVtoRGB}{wximagehsvtorgb}
619and \helpref{wxImage::RGBtoHSV}{wximagergbtohsv}, which
620converts between HSV color space and RGB color space.
621
622\pythonnote{use wxImage\_HSVValue in wxPython}
623
624
625
626\membersection{wxImage::HSVtoRGB}\label{wximagehsvtorgb}
627
628\func{wxImage::RGBValue}{HSVtoRGB}{\param{const HSVValue \& }{hsv}}
629
630Converts a color in HSV color space to RGB color space.
631
632
487659e0
VZ
633\membersection{wxImage::HasAlpha}\label{wximagehasalpha}
634
635\constfunc{bool}{HasAlpha}{\void}
636
637Returns true if this image has alpha channel, false otherwise.
638
639\wxheading{See also}
640
641\helpref{GetAlpha}{wximagegetalpha}, \helpref{SetAlpha}{wximagesetalpha}
642
07d0abae 643
1e6d9499
JS
644\membersection{wxImage::HasMask}\label{wximagehasmask}
645
646\constfunc{bool}{HasMask}{\void}
647
cc81d32f 648Returns true if there is a mask active, false otherwise.
1e6d9499 649
07d0abae 650
5e5437e0
JS
651\membersection{wxImage::GetOption}\label{wximagegetoption}
652
653\constfunc{wxString}{GetOption}{\param{const wxString\&}{ name}}
654
655Gets a user-defined option. The function is case-insensitive to {\it name}.
656
657For example, when saving as a JPEG file, the option {\bf quality} is
658used, which is a number between 0 and 100 (0 is terrible, 100 is very good).
659
660\wxheading{See also}
661
662\helpref{wxImage::SetOption}{wximagesetoption},\rtfsp
663\helpref{wxImage::GetOptionInt}{wximagegetoptionint},\rtfsp
664\helpref{wxImage::HasOption}{wximagehasoption}
665
07d0abae 666
5e5437e0
JS
667\membersection{wxImage::GetOptionInt}\label{wximagegetoptionint}
668
669\constfunc{int}{GetOptionInt}{\param{const wxString\&}{ name}}
670
671Gets a user-defined option as an integer. The function is case-insensitive to {\it name}.
672
ce045aed 673If the given option is not present, the function returns $0$. Use
07d0abae
VZ
674\helpref{wxImage::HasOption}{wximagehasoption} is $0$ is a possibly valid value
675for the option.
676
a4efa721
VZ
677Options for wxPNGHandler
678\twocolwidtha{5cm}%
679\begin{twocollist}
680\twocolitem{wxIMAGE\_OPTION\_PNG\_FORMAT}{Format for saving a PNG file.}
681\twocolitem{wxIMAGE\_OPTION\_PNG\_BITDEPTH}{Bit depth for every channel (R/G/B/A).}
682\end{twocollist}
683
684Supported values for wxIMAGE\_OPTION\_PNG\_FORMAT:
685\twocolwidtha{5cm}%
686\begin{twocollist}
687\twocolitem{wxPNG\_TYPE\_COLOUR}{Stores RGB image.}
688\twocolitem{wxPNG\_TYPE\_GREY}{Stores grey image, converts from RGB.}
689\twocolitem{wxPNG\_TYPE\_GREY\_RED}{Stores grey image, uses red value as grey.}
690\end{twocollist}
691
692
5e5437e0
JS
693\wxheading{See also}
694
695\helpref{wxImage::SetOption}{wximagesetoption},\rtfsp
07d0abae
VZ
696\helpref{wxImage::GetOption}{wximagegetoption}
697
5e5437e0
JS
698
699\membersection{wxImage::HasOption}\label{wximagehasoption}
700
701\constfunc{bool}{HasOption}{\param{const wxString\&}{ name}}
702
cc81d32f 703Returns true if the given option is present. The function is case-insensitive to {\it name}.
5e5437e0
JS
704
705\wxheading{See also}
706
707\helpref{wxImage::SetOption}{wximagesetoption},\rtfsp
708\helpref{wxImage::GetOption}{wximagegetoption},\rtfsp
709\helpref{wxImage::GetOptionInt}{wximagegetoptionint}
710
07d0abae 711
828f0936
VZ
712\membersection{wxImage::InitAlpha}\label{wximageinitalpha}
713
714\func{void}{InitAlpha}{\void}
715
716Initializes the image alpha channel data. It is an error to call it
717if the image already has alpha data. If it doesn't, alpha data will be
718by default initialized to all pixels being fully opaque. But if the image has a
719a mask colour, all mask pixels will be completely transparent.
720
721
f0e8a2d0 722\membersection{wxImage::InitStandardHandlers}\label{wximageinitstandardhandlers}
1e6d9499
JS
723
724\func{static void}{InitStandardHandlers}{\void}
725
a14e57f9 726Internal use only. Adds standard image format handlers. It only install BMP
31fd9b6b 727for the time being, which is used by wxBitmap.
1e6d9499 728
fc2171bd 729This function is called by wxWidgets on startup, and shouldn't be called by
a14e57f9 730the user.
1e6d9499
JS
731
732\wxheading{See also}
733
ce045aed 734\helpref{wxImageHandler}{wximagehandler},
b5a4a47d 735\helpref{wxInitAllImageHandlers}{wxinitallimagehandlers}
1e6d9499 736
07d0abae 737
f0e8a2d0 738\membersection{wxImage::InsertHandler}\label{wximageinserthandler}
1e6d9499
JS
739
740\func{static void}{InsertHandler}{\param{wxImageHandler*}{ handler}}
741
742Adds a handler at the start of the static list of format handlers.
743
744\docparam{handler}{A new image format handler object. There is usually only one instance
745of a given handler class in an application session.}
746
747\wxheading{See also}
748
749\helpref{wxImageHandler}{wximagehandler}
750
07d0abae 751
21dc4be5
VZ
752\membersection{wxImage::IsTransparent}\label{wximageistransparent}
753
3a40452d 754\constfunc{bool}{IsTransparent}{\param{int }{x}, \param{int }{y}, \param{unsigned char}{ threshold = $128$}}
21dc4be5
VZ
755
756Returns \true if the given pixel is transparent, i.e. either has the mask
757colour if this image has a mask or if this image has alpha channel and alpha
758value of this pixel is strictly less than \arg{threshold}.
759
760
1e6d9499
JS
761\membersection{wxImage::LoadFile}\label{wximageloadfile}
762
a61d25e6 763\func{bool}{LoadFile}{\param{const wxString\&}{ name}, \param{long}{ type = wxBITMAP\_TYPE\_ANY}, \param{int}{ index = -1}}
1e6d9499 764
a61d25e6 765\func{bool}{LoadFile}{\param{const wxString\&}{ name}, \param{const wxString\&}{ mimetype}, \param{int}{ index = -1}}
9e9ee68e 766
a14e57f9 767Loads an image from a file. If no handler type is provided, the library will
31fd9b6b 768try to autodetect the format.
1e6d9499 769
a61d25e6 770\func{bool}{LoadFile}{\param{wxInputStream\&}{ stream}, \param{long}{ type}, \param{int}{ index = -1}}
45b5751f 771
a61d25e6 772\func{bool}{LoadFile}{\param{wxInputStream\&}{ stream}, \param{const wxString\&}{ mimetype}, \param{int}{ index = -1}}
9e9ee68e 773
45b5751f
JS
774Loads an image from an input stream.
775
1e6d9499
JS
776\wxheading{Parameters}
777
31fd9b6b 778\docparam{name}{Name of the file from which to load the image.}
1e6d9499 779
31fd9b6b 780\docparam{stream}{Opened input stream from which to load the image. Currently, the stream must support seeking.}
45b5751f 781
1e6d9499
JS
782\docparam{type}{One of the following values:
783
6be663cf 784\twocolwidtha{5cm}%
1e6d9499 785\begin{twocollist}
f6fcbb63 786\twocolitem{{\bf wxBITMAP\_TYPE\_BMP}}{Load a Windows image file.}
a14e57f9 787\twocolitem{{\bf wxBITMAP\_TYPE\_GIF}}{Load a GIF image file.}
48b4e302 788\twocolitem{{\bf wxBITMAP\_TYPE\_JPEG}}{Load a JPEG image file.}
a14e57f9
SB
789\twocolitem{{\bf wxBITMAP\_TYPE\_PCX}}{Load a PCX image file.}
790\twocolitem{{\bf wxBITMAP\_TYPE\_PNG}}{Load a PNG image file.}
791\twocolitem{{\bf wxBITMAP\_TYPE\_PNM}}{Load a PNM image file.}
31fd9b6b 792\twocolitem{{\bf wxBITMAP\_TYPE\_TIF}}{Load a TIFF image file.}
b86e511a 793\twocolitem{{\bf wxBITMAP\_TYPE\_XPM}}{Load a XPM image file.}
a61d25e6
VS
794\twocolitem{{\bf wxBITMAP\_TYPE\_ICO}}{Load a Windows icon file (ICO).}
795\twocolitem{{\bf wxBITMAP\_TYPE\_CUR}}{Load a Windows cursor file (CUR).}
658974ae 796\twocolitem{\indexit{wxBITMAP\_TYPE\_ANI}}{Load a Windows animated cursor file (ANI).}
31fd9b6b
GRG
797\twocolitem{{\bf wxBITMAP\_TYPE\_ANY}}{Will try to autodetect the format.}
798\end{twocollist}}
1e6d9499 799
9e9ee68e
VS
800\docparam{mimetype}{MIME type string (for example 'image/jpeg')}
801
a61d25e6 802\docparam{index}{Index of the image to load in the case that the image file contains multiple images.
ce045aed
WS
803This is only used by GIF, ICO and TIFF handlers. The default value (-1) means
804"choose the default image" and is interpreted as the first image (index=0) by
b931f7ee 805the GIF and TIFF handler and as the largest and most colourful one by the ICO handler.}
a61d25e6 806
31fd9b6b
GRG
807\wxheading{Remarks}
808
fc2171bd 809Depending on how wxWidgets has been configured, not all formats may be available.
31fd9b6b 810
ce045aed 811Note: you can use \helpref{GetOptionInt}{wximagegetoptionint} to get the
a61d25e6
VS
812hotspot for loaded cursor file:
813\begin{verbatim}
fd94e8aa
VS
814 int hotspot_x = image.GetOptionInt(wxIMAGE_OPTION_CUR_HOTSPOT_X);
815 int hotspot_y = image.GetOptionInt(wxIMAGE_OPTION_CUR_HOTSPOT_Y);
a61d25e6
VS
816
817\end{verbatim}
37b83ca6 818
1e6d9499
JS
819\wxheading{Return value}
820
cc81d32f
VS
821true if the operation succeeded, false otherwise. If the optional index parameter is out of range,
822false is returned and a call to wxLogError() takes place.
1e6d9499
JS
823
824\wxheading{See also}
825
826\helpref{wxImage::SaveFile}{wximagesavefile}
827
f899db6d
RD
828\pythonnote{In place of a single overloaded method name, wxPython
829implements the following methods:\par
830\indented{2cm}{\begin{twocollist}
c9110876 831\twocolitem{{\bf LoadFile(filename, type)}}{Loads an image of the given
f899db6d 832type from a file}
c9110876 833\twocolitem{{\bf LoadMimeFile(filename, mimetype)}}{Loads an image of the given
f899db6d
RD
834mimetype from a file}
835\end{twocollist}}
836}
837
5873607e
VZ
838\perlnote{Methods supported by wxPerl are:\par
839\begin{itemize}
606a3178
GT
840\item{bitmap->LoadFile( name, type )}
841\item{bitmap->LoadFile( name, mimetype )}
5873607e
VZ
842\end{itemize}
843}
844
f899db6d 845
07d0abae 846
1e6d9499
JS
847\membersection{wxImage::Ok}\label{wximageok}
848
849\constfunc{bool}{Ok}{\void}
850
cc81d32f 851Returns true if image data is present.
1e6d9499 852
07d0abae 853
978d3d36
VZ
854\membersection{RGBValue::RGBValue}\label{rgbvaluergbvalue}
855
856\func{}{RGBValue}{\param{unsigned char }{r = 0}, \param{unsigned char }{g = 0}, \param{unsigned char }{b = 0}}
857
858Constructor for RGBValue, an object that contains values for red, green and blud which
859represent the value of a color. It is used by \helpref{wxImage::HSVtoRGB}{wximagehsvtorgb}
860and \helpref{wxImage::RGBtoHSV}{wximagergbtohsv}, which
861converts between HSV color space and RGB color space.
862
863\pythonnote{use wxImage\_RGBValue in wxPython}
864
865
866\membersection{wxImage::RGBtoHSV}\label{wximagergbtohsv}
867
868\func{wxImage::HSVValue}{RGBtoHSV}{\param{const RGBValue\& }{rgb}}
869
870Converts a color in RGB color space to HSV color space.
871
872
f0e8a2d0 873\membersection{wxImage::RemoveHandler}\label{wximageremovehandler}
1e6d9499
JS
874
875\func{static bool}{RemoveHandler}{\param{const wxString\& }{name}}
876
877Finds the handler with the given name, and removes it. The handler
878is not deleted.
879
880\docparam{name}{The handler name.}
881
882\wxheading{Return value}
883
cc81d32f 884true if the handler was found and removed, false otherwise.
1e6d9499
JS
885
886\wxheading{See also}
887
888\helpref{wxImageHandler}{wximagehandler}
889
07d0abae 890
e119d049
JS
891\membersection{wxImage::Mirror}\label{wximagemirror}
892
893\constfunc{wxImage}{Mirror}{\param{bool}{ horizontally = true}}
894
895Returns a mirrored copy of the image. The parameter {\it horizontally}
896indicates the orientation.
897
07d0abae 898
e119d049
JS
899\membersection{wxImage::Replace}\label{wximagereplace}
900
901\func{void}{Replace}{\param{unsigned char}{ r1}, \param{unsigned char}{ g1}, \param{unsigned char}{ b1},
902\param{unsigned char}{ r2}, \param{unsigned char}{ g2}, \param{unsigned char}{ b2}}
903
904Replaces the colour specified by {\it r1,g1,b1} by the colour {\it r2,g2,b2}.
905
07d0abae 906
e119d049
JS
907\membersection{wxImage::Rescale}\label{wximagerescale}
908
909\func{wxImage \&}{Rescale}{\param{int}{ width}, \param{int}{ height}}
910
ce045aed 911Changes the size of the image in-place by scaling it: after a call to this function,
b737ad10 912the image will have the given width and height.
e119d049
JS
913
914Returns the (modified) image itself.
915
916\wxheading{See also}
917
918\helpref{Scale}{wximagescale}
919
07d0abae 920
b737ad10
RR
921\membersection{wxImage::Resize}\label{wximageresize}
922
923\func{wxImage \&}{Resize}{\param{const wxSize\&}{ size}, \param{const wxPoint&}{ pos}, \param{int}{ red = -1}, \param{int}{ green = -1}, \param{int}{ blue = -1}}
924
ce045aed
WS
925Changes the size of the image in-place without scaling it by adding either a border
926with the given colour or cropping as necessary. The image is pasted into a new
927image with the given {\it size} and background colour at the position {\it pos}
928relative to the upper left of the new image. If {\it red = green = blue = -1}
929then use either the current mask colour if set or find, use, and set a
b737ad10
RR
930suitable mask colour for any newly exposed areas.
931
932Returns the (modified) image itself.
933
934\wxheading{See also}
935
936\helpref{Size}{wximagesize}
937
938
e119d049
JS
939\membersection{wxImage::Rotate}\label{wximagerotate}
940
941\func{wxImage}{Rotate}{\param{double}{ angle}, \param{const wxPoint\& }{rotationCentre},
942 \param{bool}{ interpolating = true}, \param{wxPoint*}{ offsetAfterRotation = NULL}}
943
944Rotates the image about the given point, by {\it angle} radians. Passing true
945to {\it interpolating} results in better image quality, but is slower. If the
946image has a mask, then the mask colour is used for the uncovered pixels in the
947rotated image background. Else, black (rgb 0, 0, 0) will be used.
948
949Returns the rotated image, leaving this image intact.
950
07d0abae 951
978d3d36
VZ
952\membersection{wxImage::RotateHue}\label{wximagerotatehue}
953
954\func{void}{RotateHue}{\param{double}{ angle}}
955
956Rotates the hue of each pixel in the image by {\it angle}, which is a double in
957the range of -1.0 to +1.0, where -1.0 corresponds to -360 degrees and +1.0 corresponds
958to +360 degrees.
959
960
e119d049
JS
961\membersection{wxImage::Rotate90}\label{wximagerotate90}
962
963\constfunc{wxImage}{Rotate90}{\param{bool}{ clockwise = true}}
964
965Returns a copy of the image rotated 90 degrees in the direction
966indicated by {\it clockwise}.
967
07d0abae 968
1e6d9499
JS
969\membersection{wxImage::SaveFile}\label{wximagesavefile}
970
d7af2fea 971\constfunc{bool}{SaveFile}{\param{const wxString\& }{name}, \param{int}{ type}}
1e6d9499 972
d7af2fea 973\constfunc{bool}{SaveFile}{\param{const wxString\& }{name}, \param{const wxString\&}{ mimetype}}
9e9ee68e 974
4fa0a5b4
VS
975Saves an image in the named file.
976
977\constfunc{bool}{SaveFile}{\param{const wxString\& }{name}}
978
979Saves an image in the named file. File type is determined from the extension of the
980file name. Note that this function may fail if the extension is not recognized! You
981can use one of the forms above to save images to files with non-standard extensions.
1e6d9499 982
d7af2fea 983\constfunc{bool}{SaveFile}{\param{wxOutputStream\& }{stream}, \param{int}{ type}}
45b5751f 984
d7af2fea 985\constfunc{bool}{SaveFile}{\param{wxOutputStream\& }{stream}, \param{const wxString\&}{ mimetype}}
9e9ee68e 986
4fa0a5b4 987Saves an image in the given stream.
45b5751f 988
1e6d9499
JS
989\wxheading{Parameters}
990
31fd9b6b 991\docparam{name}{Name of the file to save the image to.}
1e6d9499 992
31fd9b6b 993\docparam{stream}{Opened output stream to save the image to.}
45b5751f 994
4fa0a5b4 995\docparam{type}{Currently these types can be used:
1e6d9499 996
6be663cf 997\twocolwidtha{5cm}%
1e6d9499 998\begin{twocollist}
4fa0a5b4 999\twocolitem{{\bf wxBITMAP\_TYPE\_BMP}}{Save a BMP image file.}
48b4e302 1000\twocolitem{{\bf wxBITMAP\_TYPE\_JPEG}}{Save a JPEG image file.}
31fd9b6b
GRG
1001\twocolitem{{\bf wxBITMAP\_TYPE\_PNG}}{Save a PNG image file.}
1002\twocolitem{{\bf wxBITMAP\_TYPE\_PCX}}{Save a PCX image file (tries to save as 8-bit if possible, falls back to 24-bit otherwise).}
1003\twocolitem{{\bf wxBITMAP\_TYPE\_PNM}}{Save a PNM image file (as raw RGB always).}
b86e511a
VS
1004\twocolitem{{\bf wxBITMAP\_TYPE\_TIFF}}{Save a TIFF image file.}
1005\twocolitem{{\bf wxBITMAP\_TYPE\_XPM}}{Save a XPM image file.}
a61d25e6
VS
1006\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).}
1007\twocolitem{{\bf wxBITMAP\_TYPE\_CUR}}{Save a Windows cursor file (CUR).}
31fd9b6b 1008\end{twocollist}}
1e6d9499 1009
9e9ee68e
VS
1010\docparam{mimetype}{MIME type.}
1011
1e6d9499
JS
1012\wxheading{Return value}
1013
cc81d32f 1014true if the operation succeeded, false otherwise.
1e6d9499
JS
1015
1016\wxheading{Remarks}
1017
fc2171bd 1018Depending on how wxWidgets has been configured, not all formats may be available.
1e6d9499 1019
ce045aed
WS
1020Note: you can use \helpref{GetOptionInt}{wximagegetoptionint} to set the
1021hotspot before saving an image into a cursor file (default hotspot is in
a61d25e6
VS
1022the centre of the image):
1023\begin{verbatim}
fd94e8aa
VS
1024 image.SetOption(wxIMAGE_OPTION_CUR_HOTSPOT_X, hotspotX);
1025 image.SetOption(wxIMAGE_OPTION_CUR_HOTSPOT_Y, hotspotY);
a61d25e6
VS
1026
1027\end{verbatim}
1028
1e6d9499
JS
1029\wxheading{See also}
1030
1031\helpref{wxImage::LoadFile}{wximageloadfile}
1032
f899db6d
RD
1033\pythonnote{In place of a single overloaded method name, wxPython
1034implements the following methods:\par
1035\indented{2cm}{\begin{twocollist}
c9110876 1036\twocolitem{{\bf SaveFile(filename, type)}}{Saves the image using the given
f899db6d 1037type to the named file}
c9110876 1038\twocolitem{{\bf SaveMimeFile(filename, mimetype)}}{Saves the image using the given
f899db6d
RD
1039mimetype to the named file}
1040\end{twocollist}}
1041}
1042
5873607e
VZ
1043\perlnote{Methods supported by wxPerl are:\par
1044\begin{itemize}
606a3178
GT
1045\item{bitmap->SaveFile( name, type )}
1046\item{bitmap->SaveFile( name, mimetype )}
5873607e
VZ
1047\end{itemize}
1048}
1049
07d0abae 1050
1e6d9499
JS
1051\membersection{wxImage::Scale}\label{wximagescale}
1052
ce9a75d2 1053\constfunc{wxImage}{Scale}{\param{int}{ width}, \param{int}{ height}}
1e6d9499 1054
12a44087
RR
1055Returns a scaled version of the image. This is also useful for
1056scaling bitmaps in general as the only other way to scale bitmaps
ce9a75d2
VZ
1057is to blit a wxMemoryDC into another wxMemoryDC.
1058
7468b994 1059It may be mentioned that the GTK port uses this function internally
ce045aed 1060to scale bitmaps when using mapping modes in wxDC.
ce9a75d2
VZ
1061
1062Example:
1063
1064\begin{verbatim}
1065 // get the bitmap from somewhere
1066 wxBitmap bmp = ...;
1067
1068 // rescale it to have size of 32*32
1069 if ( bmp.GetWidth() != 32 || bmp.GetHeight() != 32 )
1070 {
af494043 1071 wxImage image = bmp.ConvertToImage();
b06a6b20 1072 bmp = wxBitmap(image.Scale(32, 32));
ce9a75d2
VZ
1073
1074 // another possibility:
1075 image.Rescale(32, 32);
1076 bmp = image;
1077 }
1078
1079\end{verbatim}
1080
1081\wxheading{See also}
1082
1083\helpref{Rescale}{wximagerescale}
1e6d9499 1084
07d0abae 1085
b737ad10
RR
1086\membersection{wxImage::Size}\label{wximagesize}
1087
1088\constfunc{wxImage}{Size}{\param{const wxSize\&}{ size}, \param{const wxPoint&}{ pos}, \param{int}{ red = -1}, \param{int}{ green = -1}, \param{int}{ blue = -1}}
1089
ce045aed
WS
1090Returns a resized version of this image without scaling it by adding either a border
1091with the given colour or cropping as necessary. The image is pasted into a new
1092image with the given {\it size} and background colour at the position {\it pos}
1093relative to the upper left of the new image. If {\it red = green = blue = -1}
1094then use either the current mask colour if set or find, use, and set a
b737ad10
RR
1095suitable mask colour for any newly exposed areas.
1096
1097\wxheading{See also}
1098
1099\helpref{Resize}{wximageresize}
1100
1101
487659e0
VZ
1102\membersection{wxImage::SetAlpha}\label{wximagesetalpha}
1103
60b1fda2 1104\func{void}{SetAlpha}{\param{unsigned char *}{alpha = {\tt NULL}},\param{bool}{ static\_data = \false}}
487659e0
VZ
1105
1106This function is similar to \helpref{SetData}{wximagesetdata} and has similar
1107restrictions. The pointer passed to it may however be {\tt NULL} in which case
1108the function will allocate the alpha array internally -- this is useful to add
ce045aed
WS
1109alpha channel data to an image which doesn't have any. If the pointer is not
1110{\tt NULL}, it must have one byte for each image pixel and be allocated with
60b1fda2 1111{\tt malloc()}. wxImage takes ownership of the pointer and will free it unless
7261746a 1112\arg{static\_data} parameter is set to \true -- in this case the caller should
60b1fda2 1113do it.
487659e0
VZ
1114
1115\func{void}{SetAlpha}{\param{int }{x}, \param{int }{y}, \param{unsigned char }{alpha}}
1116
1117Sets the alpha value for the given pixel. This function should only be called
1118if the image has alpha channel data, use \helpref{HasAlpha}{wximagehasalpha} to
1119check for this.
1120
07d0abae 1121
1e6d9499
JS
1122\membersection{wxImage::SetData}\label{wximagesetdata}
1123
1124\func{void}{SetData}{\param{unsigned char*}{data}}
1125
f899db6d 1126Sets the image data without performing checks. The data given must have
12a44087
RR
1127the size (width*height*3) or results will be unexpected. Don't use this
1128method if you aren't sure you know what you are doing.
1e6d9499 1129
b1ef8821 1130The data must have been allocated with {\tt malloc()}, {\large {\bf NOT}} with
487659e0 1131{\tt operator new}.
f811bc9a
MB
1132
1133After this call the pointer to the data is owned by the wxImage object,
1134that will be responsible for deleting it.
1135Do not pass to this function a pointer obtained through
1136\helpref{wxImage::GetData}{wximagegetdata}.
1137
07d0abae 1138
1e6d9499
JS
1139\membersection{wxImage::SetMask}\label{wximagesetmask}
1140
cc81d32f 1141\func{void}{SetMask}{\param{bool}{ hasMask = true}}
1e6d9499
JS
1142
1143Specifies whether there is a mask or not. The area of the mask is determined by the current mask colour.
1144
07d0abae 1145
1e6d9499
JS
1146\membersection{wxImage::SetMaskColour}\label{wximagesetmaskcolour}
1147
80793cda 1148\func{void}{SetMaskColour}{\param{unsigned char }{red}, \param{unsigned char }{green}, \param{unsigned char }{blue}}
1e6d9499 1149
b1170810 1150Sets the mask colour for this image (and tells the image to use the mask).
1e6d9499 1151
07d0abae 1152
37b83ca6
VS
1153\membersection{wxImage::SetMaskFromImage}\label{wximagesetmaskfromimage}
1154
1155\func{bool}{SetMaskFromImage}{\param{const wxImage\&}{ mask}, \param{unsigned char}{ mr}, \param{unsigned char}{ mg}, \param{unsigned char}{ mb}}
1156
1157\wxheading{Parameters}
1158
1159\docparam{mask}{The mask image to extract mask shape from. Must have same dimensions as the image.}
1160
1161\docparam{mr,mg,mb}{RGB value of pixels in {\it mask} that will be used to create the mask.}
1162
1163Sets image's mask so that the pixels that have RGB value of {\it mr,mg,mb}
1164in {\it mask} will be masked in the image. This is done by first finding an
1165unused colour in the image, setting this colour as the mask colour and then
ce045aed 1166using this colour to draw all pixels in the image who corresponding pixel
37b83ca6
VS
1167in {\it mask} has given RGB value.
1168
1169\wxheading{Return value}
1170
cc81d32f 1171Returns false if {\it mask} does not have same dimensions as the image or if
ce045aed 1172there is no unused colour left. Returns true if the mask was successfully
37b83ca6
VS
1173applied.
1174
1175\wxheading{Notes}
1176
1177Note that this method involves computing the histogram, which is
1178computationally intensive operation.
1179
07d0abae 1180
5e5437e0
JS
1181\membersection{wxImage::SetOption}\label{wximagesetoption}
1182
1183\func{void}{SetOption}{\param{const wxString\&}{ name}, \param{const wxString\&}{ value}}
1184
1185\func{void}{SetOption}{\param{const wxString\&}{ name}, \param{int}{ value}}
1186
1187Sets a user-defined option. The function is case-insensitive to {\it name}.
1188
1189For example, when saving as a JPEG file, the option {\bf quality} is
1190used, which is a number between 0 and 100 (0 is terrible, 100 is very good).
1191
1192\wxheading{See also}
1193
1194\helpref{wxImage::GetOption}{wximagegetoption},\rtfsp
1195\helpref{wxImage::GetOptionInt}{wximagegetoptionint},\rtfsp
1196\helpref{wxImage::HasOption}{wximagehasoption}
1197
07d0abae 1198
3ca6a5f0
BP
1199\membersection{wxImage::SetPalette}\label{wximagesetpalette}
1200
1201\func{void}{SetPalette}{\param{const wxPalette\&}{ palette}}
1202
b06a6b20
VS
1203Associates a palette with the image. The palette may be used when converting
1204wxImage to wxBitmap (MSW only at present) or in file save operations (none as yet).
3ca6a5f0 1205
07d0abae 1206
1e6d9499
JS
1207\membersection{wxImage::SetRGB}\label{wximagesetrgb}
1208
f6bcfd97 1209\func{void}{SetRGB}{\param{int }{x}, \param{int }{y}, \param{unsigned char }{red}, \param{unsigned char }{green}, \param{unsigned char }{blue}}
1e6d9499 1210
12a44087
RR
1211Sets the pixel at the given coordinate. This routine performs bounds-checks
1212for the coordinate so it can be considered a safe way to manipulate the
1213data, but in some cases this might be too slow so that the data will have to
ce045aed 1214be set directly. In that case you will have to get access to the image data
7468b994 1215using the \helpref{GetData}{wximagegetdata} method.
1e6d9499 1216
07d0abae 1217
b737ad10
RR
1218\membersection{wxImage::SetRGB}\label{wximagesetrgbrect}
1219
1220\func{void}{SetRGB}{\param{wxRect \& }{rect}, \param{unsigned char }{red}, \param{unsigned char }{green}, \param{unsigned char }{blue}}
1221
1222Sets the colour of the pixels within the given rectangle. This routine performs
1223bounds-checks for the coordinate so it can be considered a safe way to manipulate the
1224data.
1225
1226
f0e8a2d0 1227\membersection{wxImage::operator $=$}\label{wximageassign}
1e6d9499
JS
1228
1229\func{wxImage\& }{operator $=$}{\param{const wxImage\& }{image}}
1230
1231Assignment operator. This operator does not copy any data, but instead
1232passes a pointer to the data in {\it image} and increments a reference
1233counter. It is a fast operation.
1234
1235\wxheading{Parameters}
1236
1237\docparam{image}{Image to assign.}
1238
1239\wxheading{Return value}
1240
1241Returns 'this' object.
1242
07d0abae 1243
f0e8a2d0 1244\membersection{wxImage::operator $==$}\label{wximageequal}
1e6d9499 1245
2b5f62a0 1246\constfunc{bool}{operator $==$}{\param{const wxImage\& }{image}}
1e6d9499
JS
1247
1248Equality operator. This operator tests whether the internal data pointers are
1249equal (a fast test).
1250
1251\wxheading{Parameters}
1252
1253\docparam{image}{Image to compare with 'this'}
1254
1255\wxheading{Return value}
1256
cc81d32f 1257Returns true if the images were effectively equal, false otherwise.
1e6d9499 1258
07d0abae 1259
f0e8a2d0 1260\membersection{wxImage::operator $!=$}\label{wximagenotequal}
1e6d9499 1261
2b5f62a0 1262\constfunc{bool}{operator $!=$}{\param{const wxImage\& }{image}}
1e6d9499
JS
1263
1264Inequality operator. This operator tests whether the internal data pointers are
1265unequal (a fast test).
1266
1267\wxheading{Parameters}
1268
1269\docparam{image}{Image to compare with 'this'}
1270
1271\wxheading{Return value}
1272
cc81d32f 1273Returns true if the images were unequal, false otherwise.
1e6d9499
JS
1274
1275\section{\class{wxImageHandler}}\label{wximagehandler}
1276
1e6d9499
JS
1277This is the base class for implementing image file loading/saving, and image creation from data.
1278It is used within wxImage and is not normally seen by the application.
1279
1280If you wish to extend the capabilities of wxImage, derive a class from wxImageHandler
1281and add the handler using \helpref{wxImage::AddHandler}{wximageaddhandler} in your
1282application initialisation.
1283
48b4e302
VS
1284\wxheading{Note (Legal Issue)}
1285
954b8ae6 1286This software is based in part on the work of the Independent JPEG Group.
48b4e302 1287
fc2171bd 1288(Applies when wxWidgets is linked with JPEG support. wxJPEGHandler uses libjpeg
48b4e302
VS
1289created by IJG.)
1290
1e6d9499
JS
1291\wxheading{Derived from}
1292
1293\helpref{wxObject}{wxobject}
1294
954b8ae6
JS
1295\wxheading{Include files}
1296
1297<wx/image.h>
1298
1e6d9499
JS
1299\wxheading{See also}
1300
ce045aed 1301\helpref{wxImage}{wximage},
b5a4a47d 1302\helpref{wxInitAllImageHandlers}{wxinitallimagehandlers}
1e6d9499
JS
1303
1304\latexignore{\rtfignore{\wxheading{Members}}}
1305
07d0abae 1306
f0e8a2d0 1307\membersection{wxImageHandler::wxImageHandler}\label{wximagehandlerctor}
1e6d9499
JS
1308
1309\func{}{wxImageHandler}{\void}
1310
1311Default constructor. In your own default constructor, initialise the members
1312m\_name, m\_extension and m\_type.
1313
07d0abae 1314
f0e8a2d0 1315\membersection{wxImageHandler::\destruct{wxImageHandler}}\label{wximagehandlerdtor}
1e6d9499
JS
1316
1317\func{}{\destruct{wxImageHandler}}{\void}
1318
1319Destroys the wxImageHandler object.
1320
07d0abae 1321
f0e8a2d0 1322\membersection{wxImageHandler::GetName}\label{wximagehandlergetname}
1e6d9499
JS
1323
1324\constfunc{wxString}{GetName}{\void}
1325
1326Gets the name of this handler.
1327
07d0abae 1328
f0e8a2d0 1329\membersection{wxImageHandler::GetExtension}\label{wximagehandlergetextension}
1e6d9499
JS
1330
1331\constfunc{wxString}{GetExtension}{\void}
1332
1333Gets the file extension associated with this handler.
1334
07d0abae 1335
649d13e8 1336\membersection{wxImageHandler::GetImageCount}\label{wximagehandlergetimagecount}
7941ba11 1337
649d13e8 1338\func{int}{GetImageCount}{\param{wxInputStream\&}{ stream}}
7941ba11 1339
ce045aed 1340If the image file contains more than one image and the image handler is capable
7941ba11
RR
1341of retrieving these individually, this function will return the number of
1342available images.
1343
31fd9b6b 1344\docparam{stream}{Opened input stream for reading image data. Currently, the stream must support seeking.}
7941ba11
RR
1345
1346\wxheading{Return value}
1347
a61d25e6
VS
1348Number of available images. For most image handlers, this is 1 (exceptions
1349are TIFF and ICO formats).
7941ba11 1350
07d0abae 1351
f0e8a2d0 1352\membersection{wxImageHandler::GetType}\label{wximagehandlergettype}
1e6d9499
JS
1353
1354\constfunc{long}{GetType}{\void}
1355
1356Gets the image type associated with this handler.
1357
07d0abae 1358
f0e8a2d0 1359\membersection{wxImageHandler::GetMimeType}\label{wximagehandlergetmimetype}
9e9ee68e
VS
1360
1361\constfunc{wxString}{GetMimeType}{\void}
1362
1363Gets the MIME type associated with this handler.
1364
07d0abae 1365
1e6d9499
JS
1366\membersection{wxImageHandler::LoadFile}\label{wximagehandlerloadfile}
1367
cc81d32f 1368\func{bool}{LoadFile}{\param{wxImage* }{image}, \param{wxInputStream\&}{ stream}, \param{bool}{ verbose=true}, \param{int}{ index=0}}
1e6d9499 1369
7941ba11
RR
1370Loads a image from a stream, putting the resulting data into {\it image}. If the image file contains
1371more than one image and the image handler is capable of retrieving these individually, {\it index}
1372indicates which image to read from the stream.
1e6d9499
JS
1373
1374\wxheading{Parameters}
1375
1376\docparam{image}{The image object which is to be affected by this operation.}
1377
31fd9b6b 1378\docparam{stream}{Opened input stream for reading image data.}
7941ba11 1379
cc81d32f 1380\docparam{verbose}{If set to true, errors reported by the image handler will produce wxLogMessages.}
7941ba11
RR
1381
1382\docparam{index}{The index of the image in the file (starting from zero).}
1e6d9499
JS
1383
1384\wxheading{Return value}
1385
cc81d32f 1386true if the operation succeeded, false otherwise.
1e6d9499
JS
1387
1388\wxheading{See also}
1389
ce045aed
WS
1390\helpref{wxImage::LoadFile}{wximageloadfile},
1391\helpref{wxImage::SaveFile}{wximagesavefile},
1e6d9499
JS
1392\helpref{wxImageHandler::SaveFile}{wximagehandlersavefile}
1393
07d0abae 1394
1e6d9499
JS
1395\membersection{wxImageHandler::SaveFile}\label{wximagehandlersavefile}
1396
45b5751f 1397\func{bool}{SaveFile}{\param{wxImage* }{image}, \param{wxOutputStream\& }{stream}}
1e6d9499 1398
45b5751f 1399Saves a image in the output stream.
1e6d9499
JS
1400
1401\wxheading{Parameters}
1402
1403\docparam{image}{The image object which is to be affected by this operation.}
1404
31fd9b6b 1405\docparam{stream}{Opened output stream for writing the data.}
1e6d9499
JS
1406
1407\wxheading{Return value}
1408
cc81d32f 1409true if the operation succeeded, false otherwise.
1e6d9499
JS
1410
1411\wxheading{See also}
1412
ce045aed
WS
1413\helpref{wxImage::LoadFile}{wximageloadfile},
1414\helpref{wxImage::SaveFile}{wximagesavefile},
1e6d9499
JS
1415\helpref{wxImageHandler::LoadFile}{wximagehandlerloadfile}
1416
07d0abae 1417
f0e8a2d0 1418\membersection{wxImageHandler::SetName}\label{wximagehandlersetname}
1e6d9499
JS
1419
1420\func{void}{SetName}{\param{const wxString\& }{name}}
1421
1422Sets the handler name.
1423
1424\wxheading{Parameters}
1425
1426\docparam{name}{Handler name.}
1427
07d0abae 1428
f0e8a2d0 1429\membersection{wxImageHandler::SetExtension}\label{wximagehandlersetextension}
1e6d9499
JS
1430
1431\func{void}{SetExtension}{\param{const wxString\& }{extension}}
1432
1433Sets the handler extension.
1434
1435\wxheading{Parameters}
1436
1437\docparam{extension}{Handler extension.}
1438
07d0abae 1439
f6bcfd97 1440\membersection{wxImageHandler::SetMimeType}\label{wximagehandlersetmimetype}
1e6d9499 1441
f6bcfd97 1442\func{void}{SetMimeType}{\param{const wxString\& }{mimetype}}
1e6d9499 1443
f6bcfd97 1444Sets the handler MIME type.
1e6d9499
JS
1445
1446\wxheading{Parameters}
1447
f6bcfd97 1448\docparam{mimename}{Handler MIME type.}
9e9ee68e 1449
07d0abae 1450
f0e8a2d0 1451\membersection{wxImageHandler::SetType}\label{wximagehandlersettype}
9e9ee68e 1452
f6bcfd97 1453\func{void}{SetType}{\param{long }{type}}
9e9ee68e 1454
f6bcfd97 1455Sets the handler type.
9e9ee68e
VS
1456
1457\wxheading{Parameters}
1458
f6bcfd97 1459\docparam{name}{Handler type.}