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