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