]> git.saurik.com Git - wxWidgets.git/blame - docs/latex/wx/image.tex
added wxJPEGHandler
[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
17\wxheading{See also}
18
19\helpref{wxBitmap}{wxbitmap}
20
21\latexignore{\rtfignore{\wxheading{Members}}}
22
23\membersection{wxImage::wxImage}\label{wximageconstr}
24
25\func{}{wxImage}{\void}
26
27Default constructor.
28
29\func{}{wxImage}{\param{const wxImage\& }{image}}
30
31Copy constructor.
32
33\func{}{wxImage}{\param{const wxBitmap\&}{ bitmap}}
34
12a44087
RR
35Constructs an image from a platform-dependent bitmap. This preserves
36mask information so that bitmaps and images can be converted back
37and forth without loss in that respect.
1e6d9499
JS
38
39\func{}{wxImage}{\param{int}{ width}, \param{int}{ height}}
40
41Creates an image with the given width and height.
42
f6fcbb63 43\func{}{wxImage}{\param{const wxString\& }{name}, \param{long}{ type = wxBITMAP\_TYPE\_PNG}}
1e6d9499
JS
44
45Loads an image from a file.
46
f6fcbb63 47\func{}{wxImage}{\param{wxInputStream\& }{stream}, \param{long}{ type = wxBITMAP\_TYPE\_PNG}}
45b5751f
JS
48
49Loads an image from an input stream.
50
1e6d9499
JS
51\wxheading{Parameters}
52
53\docparam{width}{Specifies the width of the image.}
54
55\docparam{height}{Specifies the height of the image.}
56
57\docparam{name}{This refers to an image filename. Its meaning is determined by the {\it type} parameter.}
58
45b5751f
JS
59\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).}
60
1e6d9499
JS
61\docparam{type}{May be one of the following:
62
6be663cf 63\twocolwidtha{5cm}%
1e6d9499 64\begin{twocollist}
f6fcbb63
RR
65\twocolitem{{\bf \indexit{wxBITMAP\_TYPE\_BMP}}}{Load a Windows bitmap file.}
66\twocolitem{{\bf \indexit{wxBITMAP\_TYPE\_PNG}}}{Load a PNG bitmap file.}
48b4e302 67\twocolitem{{\bf \indexit{wxBITMAP\_TYPE\_JPEG}}}{Load a JPEG bitmap file.}
1e6d9499
JS
68\end{twocollist}
69
70The validity of these flags depends on the platform and wxWindows configuration.
48b4e302
VS
71If all possible wxWindows settings are used, the loading a BMP (Windows bitmap) file,
72a PNG (portable network graphics) file and a JPEG file is supported on all platforms that
12a44087 73implement wxImage.}
1e6d9499
JS
74
75\wxheading{See also}
76
77\helpref{wxImage::LoadFile}{wximageloadfile}
78
79\membersection{wxImage::\destruct{wxImage}}
80
81\func{}{\destruct{wxImage}}{\void}
82
83Destructor.
84
85\membersection{wxImage::AddHandler}\label{wximageaddhandler}
86
87\func{static void}{AddHandler}{\param{wxImageHandler*}{ handler}}
88
89Adds a handler to the end of the static list of format handlers.
90
91\docparam{handler}{A new image format handler object. There is usually only one instance
92of a given handler class in an application session.}
93
94\wxheading{See also}
95
96\helpref{wxImageHandler}{wximagehandler}
97
98\membersection{wxImage::CleanUpHandlers}
99
100\func{static void}{CleanUpHandlers}{\void}
101
102Deletes all image handlers.
103
104This function is called by wxWindows on exit.
105
106\membersection{wxImage::ConvertToBitmap}\label{wximageconverttobitmap}
107
108\constfunc{wxBitmap}{ConvertToBitmap}{\void}
109
12a44087
RR
110Converts the image to a platform-specific bitmap object. This has to be done
111to actually display an image as you cannot draw an image directly on a window.
112The resulting bitmap will use the colour depth of the current system which entails
f6fcbb63
RR
113that a (crude) colour reduction has to take place. When in 8-bit mode, this
114routine will use a color cube created on program start-up to look up colors.
115Still, the image quality won't be perfect for photo images.
1e6d9499
JS
116
117\membersection{wxImage::Create}\label{wximagecreate}
118
119\func{bool}{Create}{\param{int}{ width}, \param{int}{ height}}
120
121Creates a fresh image.
122
123\wxheading{Parameters}
124
125\docparam{width}{The width of the image in pixels.}
126
127\docparam{height}{The height of the image in pixels.}
128
129\wxheading{Return value}
130
131TRUE if the call succeeded, FALSE otherwise.
132
133\membersection{wxImage::Destroy}\label{wximagedestroy}
134
135\func{bool}{Destroy}{\void}
136
137Destroys the image data.
138
139\membersection{wxImage::FindHandler}
140
141\func{static wxImageHandler*}{FindHandler}{\param{const wxString\& }{name}}
142
143Finds the handler with the given name.
144
145\func{static wxImageHandler*}{FindHandler}{\param{const wxString\& }{extension}, \param{long}{ imageType}}
146
147Finds the handler associated with the given extension and type.
148
149\func{static wxImageHandler*}{FindHandler}{\param{long }{imageType}}
150
151Finds the handler associated with the given image type.
152
153\docparam{name}{The handler name.}
154
155\docparam{extension}{The file extension, such as ``bmp".}
156
f6fcbb63 157\docparam{imageType}{The image type, such as wxBITMAP\_TYPE\_BMP.}
1e6d9499
JS
158
159\wxheading{Return value}
160
161A pointer to the handler if found, NULL otherwise.
162
163\wxheading{See also}
164
165\helpref{wxImageHandler}{wximagehandler}
166
167\membersection{wxImage::GetBlue}\label{wximagegetblue}
168
169\constfunc{unsigned char}{GetBlue}{\param{int}{ x}, \param{int}{ y}}
170
171Returns the blue intensity at the given coordinate.
172
173\membersection{wxImage::GetData}\label{wximagegetdata}
174
175\constfunc{unsigned char*}{GetData}{\void}
176
12a44087
RR
177Returns the image data as an array. This is most often used when doing
178direct image manipulation. The return value points to an array of
179chararcters in RGBGBRGB... format.
1e6d9499
JS
180
181\membersection{wxImage::GetGreen}\label{wximagegetgreen}
182
183\constfunc{unsigned char}{GetGreen}{\param{int}{ x}, \param{int}{ y}}
184
185Returns the green intensity at the given coordinate.
186
187\membersection{wxImage::GetRed}\label{wximagegetred}
188
189\constfunc{unsigned char}{GetRed}{\param{int}{ x}, \param{int}{ y}}
190
191Returns the red intensity at the given coordinate.
192
193\membersection{wxImage::GetHandlers}
194
195\func{static wxList\&}{GetHandlers}{\void}
196
197Returns the static list of image format handlers.
198
199\wxheading{See also}
200
201\helpref{wxImageHandler}{wximagehandler}
202
203\membersection{wxImage::GetHeight}\label{wximagegetheight}
204
205\constfunc{int}{GetHeight}{\void}
206
207Gets the height of the image in pixels.
208
209\membersection{wxImage::GetMaskBlue}\label{wximagegetmaskblue}
210
211\constfunc{unsigned char}{GetMaskBlue}{\void}
212
213Gets the blue value of the mask colour.
214
215\membersection{wxImage::GetMaskGreen}\label{wximagegetmaskgreen}
216
217\constfunc{unsigned char}{GetMaskGreen}{\void}
218
219Gets the green value of the mask colour.
220
221\membersection{wxImage::GetMaskRed}\label{wximagegetmaskred}
222
223\constfunc{unsigned char}{GetMaskRed}{\void}
224
225Gets the red value of the mask colour.
226
227\membersection{wxImage::GetWidth}\label{wximagegetwidth}
228
229\constfunc{int}{GetWidth}{\void}
230
231Gets the width of the image in pixels.
232
233\wxheading{See also}
234
235\helpref{wxImage::GetHeight}{wximagegetheight}
236
237\membersection{wxImage::HasMask}\label{wximagehasmask}
238
239\constfunc{bool}{HasMask}{\void}
240
241Returns TRUE if there is a mask active, FALSE otherwise.
242
243\membersection{wxImage::InitStandardHandlers}
244
245\func{static void}{InitStandardHandlers}{\void}
246
247Adds the standard image format handlers, which, depending on wxWindows
48b4e302
VS
248configuration, can be handlers for Windows BMP (loading), PNG
249(loading and saving) and JPEG (loading and saving) file formats.
1e6d9499
JS
250
251This function is called by wxWindows on startup.
252
253\wxheading{See also}
254
255\helpref{wxImageHandler}{wximagehandler}
256
257\membersection{wxImage::InsertHandler}
258
259\func{static void}{InsertHandler}{\param{wxImageHandler*}{ handler}}
260
261Adds a handler at the start of the static list of format handlers.
262
263\docparam{handler}{A new image format handler object. There is usually only one instance
264of a given handler class in an application session.}
265
266\wxheading{See also}
267
268\helpref{wxImageHandler}{wximagehandler}
269
270\membersection{wxImage::LoadFile}\label{wximageloadfile}
271
272\func{bool}{LoadFile}{\param{const wxString\&}{ name}, \param{long}{ type}}
273
274Loads an image from a file.
275
45b5751f
JS
276\func{bool}{LoadFile}{\param{wxInputStream\&}{ stream}, \param{long}{ type}}
277
278Loads an image from an input stream.
279
1e6d9499
JS
280\wxheading{Parameters}
281
282\docparam{name}{A filename.
283The meaning of {\it name} is determined by the {\it type} parameter.}
284
45b5751f
JS
285\docparam{stream}{An input stream.
286The meaning of {\it stream} data is determined by the {\it type} parameter.}
287
1e6d9499
JS
288\docparam{type}{One of the following values:
289
6be663cf 290\twocolwidtha{5cm}%
1e6d9499 291\begin{twocollist}
f6fcbb63
RR
292\twocolitem{{\bf wxBITMAP\_TYPE\_BMP}}{Load a Windows image file.}
293\twocolitem{{\bf wxBITMAP\_TYPE\_PNG}}{Load a PNG image file.}
48b4e302 294\twocolitem{{\bf wxBITMAP\_TYPE\_JPEG}}{Load a JPEG image file.}
1e6d9499
JS
295\end{twocollist}
296
297The validity of these flags depends on the platform and wxWindows configuration.}
298
299\wxheading{Return value}
300
301TRUE if the operation succeeded, FALSE otherwise.
302
303\wxheading{See also}
304
305\helpref{wxImage::SaveFile}{wximagesavefile}
306
307\membersection{wxImage::Ok}\label{wximageok}
308
309\constfunc{bool}{Ok}{\void}
310
311Returns TRUE if image data is present.
312
313\membersection{wxImage::RemoveHandler}
314
315\func{static bool}{RemoveHandler}{\param{const wxString\& }{name}}
316
317Finds the handler with the given name, and removes it. The handler
318is not deleted.
319
320\docparam{name}{The handler name.}
321
322\wxheading{Return value}
323
324TRUE if the handler was found and removed, FALSE otherwise.
325
326\wxheading{See also}
327
328\helpref{wxImageHandler}{wximagehandler}
329
330\membersection{wxImage::SaveFile}\label{wximagesavefile}
331
332\func{bool}{SaveFile}{\param{const wxString\& }{name}, \param{int}{ type}}
333
334Saves a image in the named file.
335
45b5751f
JS
336\func{bool}{SaveFile}{\param{wxOutputStream\& }{stream}, \param{int}{ type}}
337
338Saves a image in the given stream.
339
1e6d9499
JS
340\wxheading{Parameters}
341
342\docparam{name}{A filename. The meaning of {\it name} is determined by the {\it type} parameter.}
343
45b5751f
JS
344\docparam{stream}{An output stream. The meaning of {\it stream} is determined by the {\it type} parameter.}
345
48b4e302 346\docparam{type}{Currently two types can be used:
1e6d9499 347
6be663cf 348\twocolwidtha{5cm}%
1e6d9499 349\begin{twocollist}
f6fcbb63 350\twocolitem{{\bf wxBITMAP\_TYPE\_PNG}}{Save a PNG image file.}
48b4e302 351\twocolitem{{\bf wxBITMAP\_TYPE\_JPEG}}{Save a JPEG 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
b1170810
RR
375is to blit a wxMemoryDC into another wxMemoryDC. Windows can do such
376scaling itself but in the GTK port, scaling bitmaps is done using
377this routine internally.
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
b1170810 397Sets the mask colour for this image (and tells the image to use the mask).
1e6d9499
JS
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
48b4e302
VS
463\wxheading{Note (Legal Issue)}
464
465This software is based in part on the work of
466 the Independent JPEG Group.
467
468(Applies when wxWindows is linked with JPEG support. wxJPEGHandler uses libjpeg
469created by IJG.)
470
1e6d9499
JS
471\wxheading{Derived from}
472
473\helpref{wxObject}{wxobject}
474
475\wxheading{See also}
476
477\helpref{wxImage}{wximage}
478
479\latexignore{\rtfignore{\wxheading{Members}}}
480
481\membersection{wxImageHandler::wxImageHandler}\label{wximagehandlerconstr}
482
483\func{}{wxImageHandler}{\void}
484
485Default constructor. In your own default constructor, initialise the members
486m\_name, m\_extension and m\_type.
487
488\membersection{wxImageHandler::\destruct{wxImageHandler}}
489
490\func{}{\destruct{wxImageHandler}}{\void}
491
492Destroys the wxImageHandler object.
493
494\membersection{wxImageHandler::GetName}
495
496\constfunc{wxString}{GetName}{\void}
497
498Gets the name of this handler.
499
500\membersection{wxImageHandler::GetExtension}
501
502\constfunc{wxString}{GetExtension}{\void}
503
504Gets the file extension associated with this handler.
505
506\membersection{wxImageHandler::GetType}
507
508\constfunc{long}{GetType}{\void}
509
510Gets the image type associated with this handler.
511
512\membersection{wxImageHandler::LoadFile}\label{wximagehandlerloadfile}
513
45b5751f 514\func{bool}{LoadFile}{\param{wxImage* }{image}, \param{wxInputStream\&}{ stream}}
1e6d9499 515
45b5751f 516Loads a image from a stream, putting the resulting data into {\it image}.
1e6d9499
JS
517
518\wxheading{Parameters}
519
520\docparam{image}{The image object which is to be affected by this operation.}
521
45b5751f
JS
522\docparam{stream}{Opened input stream.
523The meaning of {\it stream} is determined by the {\it type} parameter.}
1e6d9499
JS
524
525\wxheading{Return value}
526
527TRUE if the operation succeeded, FALSE otherwise.
528
529\wxheading{See also}
530
531\helpref{wxImage::LoadFile}{wximageloadfile}\\
532\helpref{wxImage::SaveFile}{wximagesavefile}\\
533\helpref{wxImageHandler::SaveFile}{wximagehandlersavefile}
534
535\membersection{wxImageHandler::SaveFile}\label{wximagehandlersavefile}
536
45b5751f 537\func{bool}{SaveFile}{\param{wxImage* }{image}, \param{wxOutputStream\& }{stream}}
1e6d9499 538
45b5751f 539Saves a image in the output stream.
1e6d9499
JS
540
541\wxheading{Parameters}
542
543\docparam{image}{The image object which is to be affected by this operation.}
544
45b5751f 545\docparam{stream}{A stream. The meaning of {\it stream} is determined by the {\it type} parameter.}
1e6d9499
JS
546
547\wxheading{Return value}
548
549TRUE if the operation succeeded, FALSE otherwise.
550
551\wxheading{See also}
552
553\helpref{wxImage::LoadFile}{wximageloadfile}\\
554\helpref{wxImage::SaveFile}{wximagesavefile}\\
555\helpref{wxImageHandler::LoadFile}{wximagehandlerloadfile}
556
557\membersection{wxImageHandler::SetName}
558
559\func{void}{SetName}{\param{const wxString\& }{name}}
560
561Sets the handler name.
562
563\wxheading{Parameters}
564
565\docparam{name}{Handler name.}
566
567\membersection{wxImageHandler::SetExtension}
568
569\func{void}{SetExtension}{\param{const wxString\& }{extension}}
570
571Sets the handler extension.
572
573\wxheading{Parameters}
574
575\docparam{extension}{Handler extension.}
576
577\membersection{wxImageHandler::SetType}
578
579\func{void}{SetType}{\param{long }{type}}
580
581Sets the handler type.
582
583\wxheading{Parameters}
584
585\docparam{name}{Handler type.}
586