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