]> git.saurik.com Git - wxWidgets.git/blame - docs/latex/wx/image.tex
Cleaning abit
[wxWidgets.git] / docs / latex / wx / image.tex
CommitLineData
1e6d9499
JS
1\section{\class{wxImage}}\label{wximage}
2
3This class encapsulates a platform-independent image. An image can be created
4from data, or using the constructor taking a wxBitmap object. An image
5can be loaded from a file in a variety of formats, and is extensible to new formats
6via image format handlers. Functions are available to set and get image bits, so
7it can be used for basic image manipulation.
8
9A wxImage cannot (currently) be drawn directly to a wxDC. Instead, a platform-specific
12a44087
RR
10wxBitmap object must be created from it, and that bitmap drawn on the wxDC, using
11wxDC::DrawBitmap.
12
13This class is currently only available under GTK and Windows.
1e6d9499
JS
14
15\wxheading{Derived from}
16
17\helpref{wxObject}{wxobject}
18
19\wxheading{See also}
20
21\helpref{wxBitmap}{wxbitmap}
22
23\latexignore{\rtfignore{\wxheading{Members}}}
24
25\membersection{wxImage::wxImage}\label{wximageconstr}
26
27\func{}{wxImage}{\void}
28
29Default constructor.
30
31\func{}{wxImage}{\param{const wxImage\& }{image}}
32
33Copy constructor.
34
35\func{}{wxImage}{\param{const wxBitmap\&}{ bitmap}}
36
12a44087
RR
37Constructs an image from a platform-dependent bitmap. This preserves
38mask information so that bitmaps and images can be converted back
39and forth without loss in that respect.
1e6d9499
JS
40
41\func{}{wxImage}{\param{int}{ width}, \param{int}{ height}}
42
43Creates an image with the given width and height.
44
12a44087 45\func{}{wxImage}{\param{const wxString\& }{name}, \param{long}{ type = wxIMAGE\_TYPE\_PNG}}
1e6d9499
JS
46
47Loads an image from a file.
48
49\wxheading{Parameters}
50
51\docparam{width}{Specifies the width of the image.}
52
53\docparam{height}{Specifies the height of the image.}
54
55\docparam{name}{This refers to an image filename. Its meaning is determined by the {\it type} parameter.}
56
57\docparam{type}{May be one of the following:
58
59\twocolwidtha{5cm}
60\begin{twocollist}
12a44087
RR
61\twocolitem{{\bf \indexit{wxIMAGE\_TYPE\_BMP}}}{Load a Windows bitmap file.}
62\twocolitem{{\bf \indexit{wxIMAGE\_TYPE\_PNG}}}{Load a PNG bitmap file.}
1e6d9499
JS
63\end{twocollist}
64
65The validity of these flags depends on the platform and wxWindows configuration.
12a44087
RR
66If all possible wxWindows settings are used, the loading a BMP (Windows bitmap) file
67and a PNG (portable network graphics) file is supported on all platforms that
68implement wxImage.}
1e6d9499
JS
69
70\wxheading{See also}
71
72\helpref{wxImage::LoadFile}{wximageloadfile}
73
74\membersection{wxImage::\destruct{wxImage}}
75
76\func{}{\destruct{wxImage}}{\void}
77
78Destructor.
79
80\membersection{wxImage::AddHandler}\label{wximageaddhandler}
81
82\func{static void}{AddHandler}{\param{wxImageHandler*}{ handler}}
83
84Adds a handler to the end of the static list of format handlers.
85
86\docparam{handler}{A new image format handler object. There is usually only one instance
87of a given handler class in an application session.}
88
89\wxheading{See also}
90
91\helpref{wxImageHandler}{wximagehandler}
92
93\membersection{wxImage::CleanUpHandlers}
94
95\func{static void}{CleanUpHandlers}{\void}
96
97Deletes all image handlers.
98
99This function is called by wxWindows on exit.
100
101\membersection{wxImage::ConvertToBitmap}\label{wximageconverttobitmap}
102
103\constfunc{wxBitmap}{ConvertToBitmap}{\void}
104
12a44087
RR
105Converts the image to a platform-specific bitmap object. This has to be done
106to actually display an image as you cannot draw an image directly on a window.
107The resulting bitmap will use the colour depth of the current system which entails
108that a (crude) colour reduction has to take place. Especially when converting
109to 8-bit (or even less) bitmaps, the routine is slow and will reduce the
110quality of the resulting bitmap. A proper set of colour reduction methods has
111not yet been written.
1e6d9499
JS
112
113\membersection{wxImage::Create}\label{wximagecreate}
114
115\func{bool}{Create}{\param{int}{ width}, \param{int}{ height}}
116
117Creates a fresh image.
118
119\wxheading{Parameters}
120
121\docparam{width}{The width of the image in pixels.}
122
123\docparam{height}{The height of the image in pixels.}
124
125\wxheading{Return value}
126
127TRUE if the call succeeded, FALSE otherwise.
128
129\membersection{wxImage::Destroy}\label{wximagedestroy}
130
131\func{bool}{Destroy}{\void}
132
133Destroys the image data.
134
135\membersection{wxImage::FindHandler}
136
137\func{static wxImageHandler*}{FindHandler}{\param{const wxString\& }{name}}
138
139Finds the handler with the given name.
140
141\func{static wxImageHandler*}{FindHandler}{\param{const wxString\& }{extension}, \param{long}{ imageType}}
142
143Finds the handler associated with the given extension and type.
144
145\func{static wxImageHandler*}{FindHandler}{\param{long }{imageType}}
146
147Finds the handler associated with the given image type.
148
149\docparam{name}{The handler name.}
150
151\docparam{extension}{The file extension, such as ``bmp".}
152
12a44087 153\docparam{imageType}{The image type, such as wxIMAGE\_TYPE\_BMP.}
1e6d9499
JS
154
155\wxheading{Return value}
156
157A pointer to the handler if found, NULL otherwise.
158
159\wxheading{See also}
160
161\helpref{wxImageHandler}{wximagehandler}
162
163\membersection{wxImage::GetBlue}\label{wximagegetblue}
164
165\constfunc{unsigned char}{GetBlue}{\param{int}{ x}, \param{int}{ y}}
166
167Returns the blue intensity at the given coordinate.
168
169\membersection{wxImage::GetData}\label{wximagegetdata}
170
171\constfunc{unsigned char*}{GetData}{\void}
172
12a44087
RR
173Returns the image data as an array. This is most often used when doing
174direct image manipulation. The return value points to an array of
175chararcters in RGBGBRGB... format.
1e6d9499
JS
176
177\membersection{wxImage::GetGreen}\label{wximagegetgreen}
178
179\constfunc{unsigned char}{GetGreen}{\param{int}{ x}, \param{int}{ y}}
180
181Returns the green intensity at the given coordinate.
182
183\membersection{wxImage::GetRed}\label{wximagegetred}
184
185\constfunc{unsigned char}{GetRed}{\param{int}{ x}, \param{int}{ y}}
186
187Returns the red intensity at the given coordinate.
188
189\membersection{wxImage::GetHandlers}
190
191\func{static wxList\&}{GetHandlers}{\void}
192
193Returns the static list of image format handlers.
194
195\wxheading{See also}
196
197\helpref{wxImageHandler}{wximagehandler}
198
199\membersection{wxImage::GetHeight}\label{wximagegetheight}
200
201\constfunc{int}{GetHeight}{\void}
202
203Gets the height of the image in pixels.
204
205\membersection{wxImage::GetMaskBlue}\label{wximagegetmaskblue}
206
207\constfunc{unsigned char}{GetMaskBlue}{\void}
208
209Gets the blue value of the mask colour.
210
211\membersection{wxImage::GetMaskGreen}\label{wximagegetmaskgreen}
212
213\constfunc{unsigned char}{GetMaskGreen}{\void}
214
215Gets the green value of the mask colour.
216
217\membersection{wxImage::GetMaskRed}\label{wximagegetmaskred}
218
219\constfunc{unsigned char}{GetMaskRed}{\void}
220
221Gets the red value of the mask colour.
222
223\membersection{wxImage::GetWidth}\label{wximagegetwidth}
224
225\constfunc{int}{GetWidth}{\void}
226
227Gets the width of the image in pixels.
228
229\wxheading{See also}
230
231\helpref{wxImage::GetHeight}{wximagegetheight}
232
233\membersection{wxImage::HasMask}\label{wximagehasmask}
234
235\constfunc{bool}{HasMask}{\void}
236
237Returns TRUE if there is a mask active, FALSE otherwise.
238
239\membersection{wxImage::InitStandardHandlers}
240
241\func{static void}{InitStandardHandlers}{\void}
242
243Adds the standard image format handlers, which, depending on wxWindows
12a44087
RR
244configuration, can be handlers for Windows BMP (loading) and PNG
245(loading and saving) file formats.
1e6d9499
JS
246
247This function is called by wxWindows on startup.
248
249\wxheading{See also}
250
251\helpref{wxImageHandler}{wximagehandler}
252
253\membersection{wxImage::InsertHandler}
254
255\func{static void}{InsertHandler}{\param{wxImageHandler*}{ handler}}
256
257Adds a handler at the start of the static list of format handlers.
258
259\docparam{handler}{A new image format handler object. There is usually only one instance
260of a given handler class in an application session.}
261
262\wxheading{See also}
263
264\helpref{wxImageHandler}{wximagehandler}
265
266\membersection{wxImage::LoadFile}\label{wximageloadfile}
267
268\func{bool}{LoadFile}{\param{const wxString\&}{ name}, \param{long}{ type}}
269
270Loads an image from a file.
271
272\wxheading{Parameters}
273
274\docparam{name}{A filename.
275The meaning of {\it name} is determined by the {\it type} parameter.}
276
277\docparam{type}{One of the following values:
278
279\twocolwidtha{5cm}
280\begin{twocollist}
12a44087
RR
281\twocolitem{{\bf wxIMAGE\_TYPE\_BMP}}{Load a Windows image file.}
282\twocolitem{{\bf wxIMAGE\_TYPE\_PNG}}{Load a PNG image file.}
1e6d9499
JS
283\end{twocollist}
284
285The validity of these flags depends on the platform and wxWindows configuration.}
286
287\wxheading{Return value}
288
289TRUE if the operation succeeded, FALSE otherwise.
290
291\wxheading{See also}
292
293\helpref{wxImage::SaveFile}{wximagesavefile}
294
295\membersection{wxImage::Ok}\label{wximageok}
296
297\constfunc{bool}{Ok}{\void}
298
299Returns TRUE if image data is present.
300
301\membersection{wxImage::RemoveHandler}
302
303\func{static bool}{RemoveHandler}{\param{const wxString\& }{name}}
304
305Finds the handler with the given name, and removes it. The handler
306is not deleted.
307
308\docparam{name}{The handler name.}
309
310\wxheading{Return value}
311
312TRUE if the handler was found and removed, FALSE otherwise.
313
314\wxheading{See also}
315
316\helpref{wxImageHandler}{wximagehandler}
317
318\membersection{wxImage::SaveFile}\label{wximagesavefile}
319
320\func{bool}{SaveFile}{\param{const wxString\& }{name}, \param{int}{ type}}
321
322Saves a image in the named file.
323
324\wxheading{Parameters}
325
326\docparam{name}{A filename. The meaning of {\it name} is determined by the {\it type} parameter.}
327
12a44087 328\docparam{type}{Currently only one type can be used:
1e6d9499
JS
329
330\twocolwidtha{5cm}
331\begin{twocollist}
12a44087 332\twocolitem{{\bf wxIMAGE\_TYPE\_PNG}}{Save a PNG image file.}
1e6d9499
JS
333\end{twocollist}
334
12a44087
RR
335The validity of these flags depends on the platform and wxWindows configuration
336as well as user-added handlers.}
1e6d9499
JS
337
338\wxheading{Return value}
339
340TRUE if the operation succeeded, FALSE otherwise.
341
342\wxheading{Remarks}
343
344Depending on how wxWindows has been configured, not all formats may be available.
345
346\wxheading{See also}
347
348\helpref{wxImage::LoadFile}{wximageloadfile}
349
350\membersection{wxImage::Scale}\label{wximagescale}
351
352\func{wxImage}{Scale}{\param{int}{ width}, \param{int}{ height}}
353
12a44087
RR
354Returns a scaled version of the image. This is also useful for
355scaling bitmaps in general as the only other way to scale bitmaps
356is do blit a wxMemoryDC into another wxMemoryDC. Windows can such scaling
357itself, but on GTK scaling bitmaps is done using this routine
358internally.
1e6d9499
JS
359
360\membersection{wxImage::SetData}\label{wximagesetdata}
361
362\func{void}{SetData}{\param{unsigned char*}{data}}
363
12a44087
RR
364Sets the image data without performing checks. The data given must have
365the size (width*height*3) or results will be unexpected. Don't use this
366method if you aren't sure you know what you are doing.
1e6d9499
JS
367
368\membersection{wxImage::SetMask}\label{wximagesetmask}
369
370\func{void}{SetMask}{\param{bool}{ hasMask = TRUE}}
371
372Specifies whether there is a mask or not. The area of the mask is determined by the current mask colour.
373
374\membersection{wxImage::SetMaskColour}\label{wximagesetmaskcolour}
375
376\func{void}{SetMaskColour}{\param{unsigned char }{red}, \param{unsigned char }{blue}, \param{unsigned char }{green}}
377
378Sets the mask colour for this image.
379
380\membersection{wxImage::SetRGB}\label{wximagesetrgb}
381
382\func{void}{SetRGB}{\param{int }{x}, \param{int }{y}, \param{unsigned char }{red}, \param{unsigned char }{blue}, \param{unsigned char }{green}}
383
12a44087
RR
384Sets the pixel at the given coordinate. This routine performs bounds-checks
385for the coordinate so it can be considered a safe way to manipulate the
386data, but in some cases this might be too slow so that the data will have to
387be set directly. In that case you have to get that data by calling GetData().
1e6d9499
JS
388
389\membersection{wxImage::operator $=$}
390
391\func{wxImage\& }{operator $=$}{\param{const wxImage\& }{image}}
392
393Assignment operator. This operator does not copy any data, but instead
394passes a pointer to the data in {\it image} and increments a reference
395counter. It is a fast operation.
396
397\wxheading{Parameters}
398
399\docparam{image}{Image to assign.}
400
401\wxheading{Return value}
402
403Returns 'this' object.
404
405\membersection{wxImage::operator $==$}
406
407\func{bool}{operator $==$}{\param{const wxImage\& }{image}}
408
409Equality operator. This operator tests whether the internal data pointers are
410equal (a fast test).
411
412\wxheading{Parameters}
413
414\docparam{image}{Image to compare with 'this'}
415
416\wxheading{Return value}
417
418Returns TRUE if the images were effectively equal, FALSE otherwise.
419
420\membersection{wxImage::operator $!=$}
421
422\func{bool}{operator $!=$}{\param{const wxImage\& }{image}}
423
424Inequality operator. This operator tests whether the internal data pointers are
425unequal (a fast test).
426
427\wxheading{Parameters}
428
429\docparam{image}{Image to compare with 'this'}
430
431\wxheading{Return value}
432
433Returns TRUE if the images were unequal, FALSE otherwise.
434
435\section{\class{wxImageHandler}}\label{wximagehandler}
436
1e6d9499
JS
437This is the base class for implementing image file loading/saving, and image creation from data.
438It is used within wxImage and is not normally seen by the application.
439
440If you wish to extend the capabilities of wxImage, derive a class from wxImageHandler
441and add the handler using \helpref{wxImage::AddHandler}{wximageaddhandler} in your
442application initialisation.
443
444\wxheading{Derived from}
445
446\helpref{wxObject}{wxobject}
447
448\wxheading{See also}
449
450\helpref{wxImage}{wximage}
451
452\latexignore{\rtfignore{\wxheading{Members}}}
453
454\membersection{wxImageHandler::wxImageHandler}\label{wximagehandlerconstr}
455
456\func{}{wxImageHandler}{\void}
457
458Default constructor. In your own default constructor, initialise the members
459m\_name, m\_extension and m\_type.
460
461\membersection{wxImageHandler::\destruct{wxImageHandler}}
462
463\func{}{\destruct{wxImageHandler}}{\void}
464
465Destroys the wxImageHandler object.
466
467\membersection{wxImageHandler::GetName}
468
469\constfunc{wxString}{GetName}{\void}
470
471Gets the name of this handler.
472
473\membersection{wxImageHandler::GetExtension}
474
475\constfunc{wxString}{GetExtension}{\void}
476
477Gets the file extension associated with this handler.
478
479\membersection{wxImageHandler::GetType}
480
481\constfunc{long}{GetType}{\void}
482
483Gets the image type associated with this handler.
484
485\membersection{wxImageHandler::LoadFile}\label{wximagehandlerloadfile}
486
487\func{bool}{LoadFile}{\param{wxImage* }{image}, \param{const wxString\&}{ name}}
488
489Loads a image from a file or resource, putting the resulting data into {\it image}.
490
491\wxheading{Parameters}
492
493\docparam{image}{The image object which is to be affected by this operation.}
494
495\docparam{name}{Either a filename or a Windows resource name.
496The meaning of {\it name} is determined by the {\it type} parameter.}
497
498\wxheading{Return value}
499
500TRUE if the operation succeeded, FALSE otherwise.
501
502\wxheading{See also}
503
504\helpref{wxImage::LoadFile}{wximageloadfile}\\
505\helpref{wxImage::SaveFile}{wximagesavefile}\\
506\helpref{wxImageHandler::SaveFile}{wximagehandlersavefile}
507
508\membersection{wxImageHandler::SaveFile}\label{wximagehandlersavefile}
509
510\func{bool}{SaveFile}{\param{wxImage* }{image}, \param{const wxString\& }{name}}
511
512Saves a image in the named file.
513
514\wxheading{Parameters}
515
516\docparam{image}{The image object which is to be affected by this operation.}
517
518\docparam{name}{A filename. The meaning of {\it name} is determined by the {\it type} parameter.}
519
520\wxheading{Return value}
521
522TRUE if the operation succeeded, FALSE otherwise.
523
524\wxheading{See also}
525
526\helpref{wxImage::LoadFile}{wximageloadfile}\\
527\helpref{wxImage::SaveFile}{wximagesavefile}\\
528\helpref{wxImageHandler::LoadFile}{wximagehandlerloadfile}
529
530\membersection{wxImageHandler::SetName}
531
532\func{void}{SetName}{\param{const wxString\& }{name}}
533
534Sets the handler name.
535
536\wxheading{Parameters}
537
538\docparam{name}{Handler name.}
539
540\membersection{wxImageHandler::SetExtension}
541
542\func{void}{SetExtension}{\param{const wxString\& }{extension}}
543
544Sets the handler extension.
545
546\wxheading{Parameters}
547
548\docparam{extension}{Handler extension.}
549
550\membersection{wxImageHandler::SetType}
551
552\func{void}{SetType}{\param{long }{type}}
553
554Sets the handler type.
555
556\wxheading{Parameters}
557
558\docparam{name}{Handler type.}
559
560