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