]> git.saurik.com Git - wxWidgets.git/blob - docs/latex/wx/bitmap.tex
added wxDataViewIconTextRenderer
[wxWidgets.git] / docs / latex / wx / bitmap.tex
1 \section{\class{wxBitmap}}\label{wxbitmap}
2
3 %\overview{Overview}{wxbitmapoverview}
4 %
5 This class encapsulates the concept of a platform-dependent bitmap,
6 either monochrome or colour or colour with alpha channel support.
7
8 \wxheading{Derived from}
9
10 \helpref{wxGDIObject}{wxgdiobject}\\
11 \helpref{wxObject}{wxobject}
12
13 \wxheading{Include files}
14
15 <wx/bitmap.h>
16
17 \wxheading{Library}
18
19 \helpref{wxCore}{librarieslist}
20
21 \wxheading{Predefined objects}
22
23 Objects:
24
25 {\bf wxNullBitmap}
26
27 \wxheading{See also}
28
29 \helpref{wxBitmap overview}{wxbitmapoverview},
30 \helpref{supported bitmap file formats}{supportedbitmapformats},
31 \helpref{wxDC::Blit}{wxdcblit},
32 \helpref{wxIcon}{wxicon}, \helpref{wxCursor}{wxcursor}, \helpref{wxBitmap}{wxbitmap},
33 \helpref{wxMemoryDC}{wxmemorydc}
34
35 \latexignore{\rtfignore{\wxheading{Members}}}
36
37 \membersection{wxBitmap::wxBitmap}\label{wxbitmapctor}
38
39 \func{}{wxBitmap}{\void}
40
41 Default constructor.
42
43 \func{}{wxBitmap}{\param{const wxBitmap\& }{bitmap}}
44
45 Copy constructor, uses \helpref{reference counting}{trefcount}.
46 To make a real copy, you can use:
47
48 \begin{verbatim}
49 wxBitmap newBitmap = oldBitmap.GetSubBitmap(
50 wxRect(0, 0, oldBitmap.GetWidth(), oldBitmap.GetHeight()));
51 \end{verbatim}
52
53 \func{}{wxBitmap}{\param{const void*}{ data}, \param{int}{ type}, \param{int}{ width}, \param{int}{ height}, \param{int}{ depth = -1}}
54
55 Creates a bitmap from the given data which is interpreted in platform-dependent
56 manner.
57
58 \func{}{wxBitmap}{\param{const char}{ bits[]}, \param{int}{ width}, \param{int}{ height}\\
59 \param{int}{ depth = 1}}
60
61 Creates a bitmap from an array of bits.
62
63 You should only use this function for monochrome bitmaps ({\it depth} 1) in
64 portable programs: in this case the {\it bits} parameter should contain an XBM
65 image.
66
67 For other bit depths, the behaviour is platform dependent: under Windows, the
68 data is passed without any changes to the underlying {\tt CreateBitmap()} API.
69 Under other platforms, only monochrome bitmaps may be created using this
70 constructor and \helpref{wxImage}{wximage} should be used for creating colour
71 bitmaps from static data.
72
73 \func{}{wxBitmap}{\param{int}{ width}, \param{int}{ height}, \param{int}{ depth = -1}}
74
75 Creates a new bitmap. A depth of -1 indicates the depth of the current screen
76 or visual. Some platforms only support 1 for monochrome and -1 for the current
77 colour setting. Beginning with version 2.5.4 of wxWidgets a depth of 32 including
78 an alpha channel is supported under MSW, Mac and GTK+.
79
80 \func{}{wxBitmap}{\param{const char* const*}{ bits}}
81
82 Creates a bitmap from XPM data.
83
84 \func{}{wxBitmap}{\param{const wxString\& }{name}, \param{long}{ type}}
85
86 Loads a bitmap from a file or resource.
87
88 \func{}{wxBitmap}{\param{const wxImage\&}{ img}, \param{int}{ depth = -1}}
89
90 Creates bitmap object from the image. This has to be done
91 to actually display an image as you cannot draw an image directly on a window.
92 The resulting bitmap will use the provided colour depth (or that of the
93 current system if depth is -1) which entails that a colour reduction has
94 to take place.
95
96 When in 8-bit mode (PseudoColour mode), the GTK port will use a color cube created
97 on program start-up to look up colors. This ensures a very fast conversion, but
98 the image quality won't be perfect (and could be better for photo images using more
99 sophisticated dithering algorithms).
100
101 On Windows, if there is a palette present (set with SetPalette), it will be used when
102 creating the wxBitmap (most useful in 8-bit display mode). On other platforms,
103 the palette is currently ignored.
104
105 \wxheading{Parameters}
106
107 \docparam{bits}{Specifies an array of pixel values.}
108
109 \docparam{width}{Specifies the width of the bitmap.}
110
111 \docparam{height}{Specifies the height of the bitmap.}
112
113 \docparam{depth}{Specifies the depth of the bitmap. If this is omitted, the display depth of the
114 screen is used.}
115
116 \docparam{name}{This can refer to a resource name under MS Windows, or a filename under MS Windows and X.
117 Its meaning is determined by the {\it type} parameter.}
118
119 \docparam{type}{May be one of the following:
120
121 \twocolwidtha{5cm}
122 \begin{twocollist}
123 \twocolitem{\indexit{wxBITMAP\_TYPE\_BMP}}{Load a Windows bitmap file.}
124 \twocolitem{\indexit{wxBITMAP\_TYPE\_BMP\_RESOURCE}}{Load a Windows bitmap resource from the executable. Windows only.}
125 \twocolitem{\indexit{wxBITMAP\_TYPE\_PICT\_RESOURCE}}{Load a PICT image resource from the executable. Mac OS only.}
126 \twocolitem{\indexit{wxBITMAP\_TYPE\_GIF}}{Load a GIF bitmap file.}
127 \twocolitem{\indexit{wxBITMAP\_TYPE\_XBM}}{Load an X bitmap file.}
128 \twocolitem{\indexit{wxBITMAP\_TYPE\_XPM}}{Load an XPM bitmap file.}
129 \end{twocollist}
130
131 The validity of these flags depends on the platform and wxWidgets configuration.
132 If all possible wxWidgets settings are used, the Windows platform supports BMP file, BMP resource,
133 XPM data, and XPM. Under wxGTK, the available formats are BMP file, XPM data, XPM file, and PNG file.
134 Under wxMotif, the available formats are XBM data, XBM file, XPM data, XPM file.
135
136 In addition, wxBitmap can read all formats that \helpref{wxImage}{wximage} can, which currently include
137 wxBITMAP\_TYPE\_JPEG, wxBITMAP\_TYPE\_TIF, wxBITMAP\_TYPE\_PNG, wxBITMAP\_TYPE\_GIF, wxBITMAP\_TYPE\_PCX,
138 and wxBITMAP\_TYPE\_PNM. Of course, you must have wxImage handlers loaded. }
139
140 \docparam{img}{Platform-independent wxImage object.}
141
142 \wxheading{Remarks}
143
144 The first form constructs a bitmap object with no data; an assignment or another member function such as Create
145 or LoadFile must be called subsequently.
146
147 The second and third forms provide copy constructors. Note that these do not copy the
148 bitmap data, but instead a pointer to the data, keeping a reference count. They are therefore
149 very efficient operations.
150
151 The fourth form constructs a bitmap from data whose type and value depends on
152 the value of the {\it type} argument.
153
154 The fifth form constructs a (usually monochrome) bitmap from an array of pixel values, under both
155 X and Windows.
156
157 The sixth form constructs a new bitmap.
158
159 The seventh form constructs a bitmap from pixmap (XPM) data, if wxWidgets has been configured
160 to incorporate this feature.
161
162 To use this constructor, you must first include an XPM file. For
163 example, assuming that the file {\tt mybitmap.xpm} contains an XPM array
164 of character pointers called mybitmap:
165
166 \begin{verbatim}
167 #include "mybitmap.xpm"
168
169 ...
170
171 wxBitmap *bitmap = new wxBitmap(mybitmap);
172 \end{verbatim}
173
174 The eighth form constructs a bitmap from a file or resource. {\it name} can refer
175 to a resource name under MS Windows, or a filename under MS Windows and X.
176
177 Under Windows, {\it type} defaults to wxBITMAP\_TYPE\_BMP\_RESOURCE.
178 Under X, {\it type} defaults to wxBITMAP\_TYPE\_XPM.
179
180 \wxheading{See also}
181
182 \helpref{wxBitmap::LoadFile}{wxbitmaploadfile}
183
184 \pythonnote{Constructors supported by wxPython are:\par
185 \indented{2cm}{\begin{twocollist}
186 \twocolitem{{\bf wxBitmap(name, flag)}}{Loads a bitmap from a file}
187 \twocolitem{{\bf wxEmptyBitmap(width, height, depth = -1)}}{Creates an
188 empty bitmap with the given specifications}
189 \twocolitem{{\bf wxBitmapFromXPMData(listOfStrings)}}{Create a bitmap
190 from a Python list of strings whose contents are XPM data.}
191 \twocolitem{{\bf wxBitmapFromBits(bits, width, height,
192 depth=-1)}}{Create a bitmap from an array of bits contained in a
193 string.}
194 \twocolitem{{\bf wxBitmapFromImage(image, depth=-1)}}{Convert a
195 wxImage to a wxBitmap.}
196 \end{twocollist}}
197 }
198
199 \perlnote{Constructors supported by wxPerl are:\par
200 \begin{itemize}
201 \item{Wx::Bitmap->new( width, height, depth = -1 )}
202 \item{Wx::Bitmap->new( name, type )}
203 \item{Wx::Bitmap->new( icon )}
204 \item{Wx::Bitmap->newFromBits( bits, width, height, depth = 1 )}
205 \item{Wx::Bitmap->newFromXPM( data )}
206 \end{itemize}
207 }
208
209 \membersection{wxBitmap::\destruct{wxBitmap}}\label{wxbitmapdtor}
210
211 \func{}{\destruct{wxBitmap}}{\void}
212
213 Destructor.
214 See \helpref{reference-counted object destruction}{refcountdestruct} for more info.
215
216 If the application omits to delete the bitmap explicitly, the bitmap will be
217 destroyed automatically by wxWidgets when the application exits.
218
219 Do not delete a bitmap that is selected into a memory device context.
220
221 \membersection{wxBitmap::AddHandler}\label{wxbitmapaddhandler}
222
223 \func{static void}{AddHandler}{\param{wxBitmapHandler*}{ handler}}
224
225 Adds a handler to the end of the static list of format handlers.
226
227 \docparam{handler}{A new bitmap format handler object. There is usually only one instance
228 of a given handler class in an application session.}
229
230 \wxheading{See also}
231
232 \helpref{wxBitmapHandler}{wxbitmaphandler}
233
234 \membersection{wxBitmap::CleanUpHandlers}\label{wxbitmapcleanuphandlers}
235
236 \func{static void}{CleanUpHandlers}{\void}
237
238 Deletes all bitmap handlers.
239
240 This function is called by wxWidgets on exit.
241
242 \membersection{wxBitmap::ConvertToImage}\label{wxbitmapconverttoimage}
243
244 \func{wxImage}{ConvertToImage}{\void}
245
246 Creates an image from a platform-dependent bitmap. This preserves
247 mask information so that bitmaps and images can be converted back
248 and forth without loss in that respect.
249
250 \membersection{wxBitmap::CopyFromIcon}\label{wxbitmapcopyfromicon}
251
252 \func{bool}{CopyFromIcon}{\param{const wxIcon\&}{ icon}}
253
254 Creates the bitmap from an icon.
255
256 \membersection{wxBitmap::Create}\label{wxbitmapcreate}
257
258 \func{virtual bool}{Create}{\param{int}{ width}, \param{int}{ height}, \param{int}{ depth = -1}}
259
260 Creates a fresh bitmap. If the final argument is omitted, the display depth of
261 the screen is used.
262
263 \func{virtual bool}{Create}{\param{const void*}{ data}, \param{int}{ type}, \param{int}{ width}, \param{int}{ height}, \param{int}{ depth = -1}}
264
265 Creates a bitmap from the given data, which can be of arbitrary type.
266
267 \wxheading{Parameters}
268
269 \docparam{width}{The width of the bitmap in pixels.}
270
271 \docparam{height}{The height of the bitmap in pixels.}
272
273 \docparam{depth}{The depth of the bitmap in pixels. If this is -1, the screen depth is used.}
274
275 \docparam{data}{Data whose type depends on the value of {\it type}.}
276
277 \docparam{type}{A bitmap type identifier - see \helpref{wxBitmap::wxBitmap}{wxbitmapctor} for a list
278 of possible values.}
279
280 \wxheading{Return value}
281
282 true if the call succeeded, false otherwise.
283
284 \wxheading{Remarks}
285
286 The first form works on all platforms. The portability of the second form depends on the
287 type of data.
288
289 \wxheading{See also}
290
291 \helpref{wxBitmap::wxBitmap}{wxbitmapctor}
292
293 \membersection{wxBitmap::FindHandler}\label{wxbitmapfindhandler}
294
295 \func{static wxBitmapHandler*}{FindHandler}{\param{const wxString\& }{name}}
296
297 Finds the handler with the given name.
298
299 \func{static wxBitmapHandler*}{FindHandler}{\param{const wxString\& }{extension}, \param{wxBitmapType}{ bitmapType}}
300
301 Finds the handler associated with the given extension and type.
302
303 \func{static wxBitmapHandler*}{FindHandler}{\param{wxBitmapType }{bitmapType}}
304
305 Finds the handler associated with the given bitmap type.
306
307 \docparam{name}{The handler name.}
308
309 \docparam{extension}{The file extension, such as ``bmp".}
310
311 \docparam{bitmapType}{The bitmap type, such as wxBITMAP\_TYPE\_BMP.}
312
313 \wxheading{Return value}
314
315 A pointer to the handler if found, NULL otherwise.
316
317 \wxheading{See also}
318
319 \helpref{wxBitmapHandler}{wxbitmaphandler}
320
321 \membersection{wxBitmap::GetDepth}\label{wxbitmapgetdepth}
322
323 \constfunc{int}{GetDepth}{\void}
324
325 Gets the colour depth of the bitmap. A value of 1 indicates a
326 monochrome bitmap.
327
328 \membersection{wxBitmap::GetHandlers}\label{wxbitmapgethandlers}
329
330 \func{static wxList\&}{GetHandlers}{\void}
331
332 Returns the static list of bitmap format handlers.
333
334 \wxheading{See also}
335
336 \helpref{wxBitmapHandler}{wxbitmaphandler}
337
338 \membersection{wxBitmap::GetHeight}\label{wxbitmapgetheight}
339
340 \constfunc{int}{GetHeight}{\void}
341
342 Gets the height of the bitmap in pixels.
343
344 \membersection{wxBitmap::GetPalette}\label{wxbitmapgetpalette}
345
346 \constfunc{wxPalette*}{GetPalette}{\void}
347
348 Gets the associated palette (if any) which may have been loaded from a file
349 or set for the bitmap.
350
351 \wxheading{See also}
352
353 \helpref{wxPalette}{wxpalette}
354
355 \membersection{wxBitmap::GetMask}\label{wxbitmapgetmask}
356
357 \constfunc{wxMask*}{GetMask}{\void}
358
359 Gets the associated mask (if any) which may have been loaded from a file
360 or set for the bitmap.
361
362 \wxheading{See also}
363
364 \helpref{wxBitmap::SetMask}{wxbitmapsetmask}, \helpref{wxMask}{wxmask}
365
366 \membersection{wxBitmap::GetWidth}\label{wxbitmapgetwidth}
367
368 \constfunc{int}{GetWidth}{\void}
369
370 Gets the width of the bitmap in pixels.
371
372 \wxheading{See also}
373
374 \helpref{wxBitmap::GetHeight}{wxbitmapgetheight}
375
376 \membersection{wxBitmap::GetSubBitmap}\label{wxbitmapgetsubbitmap}
377
378 \constfunc{wxBitmap}{GetSubBitmap}{\param{const wxRect\&}{rect}}
379
380 Returns a sub bitmap of the current one as long as the rect belongs entirely to
381 the bitmap. This function preserves bit depth and mask information.
382
383 \membersection{wxBitmap::InitStandardHandlers}\label{wxbitmapinitstandardhandlers}
384
385 \func{static void}{InitStandardHandlers}{\void}
386
387 Adds the standard bitmap format handlers, which, depending on wxWidgets
388 configuration, can be handlers for Windows bitmap, Windows bitmap resource, and XPM.
389
390 This function is called by wxWidgets on startup.
391
392 \wxheading{See also}
393
394 \helpref{wxBitmapHandler}{wxbitmaphandler}
395
396 \membersection{wxBitmap::InsertHandler}\label{wxbitmapinserthandler}
397
398 \func{static void}{InsertHandler}{\param{wxBitmapHandler*}{ handler}}
399
400 Adds a handler at the start of the static list of format handlers.
401
402 \docparam{handler}{A new bitmap format handler object. There is usually only one instance
403 of a given handler class in an application session.}
404
405 \wxheading{See also}
406
407 \helpref{wxBitmapHandler}{wxbitmaphandler}
408
409 \membersection{wxBitmap::LoadFile}\label{wxbitmaploadfile}
410
411 \func{bool}{LoadFile}{\param{const wxString\&}{ name}, \param{wxBitmapType}{ type}}
412
413 Loads a bitmap from a file or resource.
414
415 \wxheading{Parameters}
416
417 \docparam{name}{Either a filename or a Windows resource name.
418 The meaning of {\it name} is determined by the {\it type} parameter.}
419
420 \docparam{type}{One of the following values:
421
422 \twocolwidtha{5cm}
423 \begin{twocollist}
424 \twocolitem{{\bf wxBITMAP\_TYPE\_BMP}}{Load a Windows bitmap file.}
425 \twocolitem{{\bf wxBITMAP\_TYPE\_BMP\_RESOURCE}}{Load a Windows bitmap resource from the executable.}
426 \twocolitem{{\bf wxBITMAP\_TYPE\_PICT\_RESOURCE}}{Load a PICT image resource from the executable. Mac OS only.}
427 \twocolitem{{\bf wxBITMAP\_TYPE\_GIF}}{Load a GIF bitmap file.}
428 \twocolitem{{\bf wxBITMAP\_TYPE\_XBM}}{Load an X bitmap file.}
429 \twocolitem{{\bf wxBITMAP\_TYPE\_XPM}}{Load an XPM bitmap file.}
430 \end{twocollist}
431
432 The validity of these flags depends on the platform and wxWidgets configuration.
433
434 In addition, wxBitmap can read all formats that \helpref{wxImage}{wximage} can
435 (wxBITMAP\_TYPE\_JPEG, wxBITMAP\_TYPE\_PNG, wxBITMAP\_TYPE\_GIF, wxBITMAP\_TYPE\_PCX, wxBITMAP\_TYPE\_PNM).
436 (Of course you must have wxImage handlers loaded.) }
437
438 \wxheading{Return value}
439
440 true if the operation succeeded, false otherwise.
441
442 \wxheading{Remarks}
443
444 A palette may be associated with the bitmap if one exists (especially for
445 colour Windows bitmaps), and if the code supports it. You can check
446 if one has been created by using the \helpref{GetPalette}{wxbitmapgetpalette} member.
447
448 \wxheading{See also}
449
450 \helpref{wxBitmap::SaveFile}{wxbitmapsavefile}
451
452 \membersection{wxBitmap::IsOk}\label{wxbitmapisok}
453
454 \constfunc{bool}{IsOk}{\void}
455
456 Returns true if bitmap data is present.
457
458 \membersection{wxBitmap::RemoveHandler}\label{wxbitmapremovehandler}
459
460 \func{static bool}{RemoveHandler}{\param{const wxString\& }{name}}
461
462 Finds the handler with the given name, and removes it. The handler
463 is not deleted.
464
465 \docparam{name}{The handler name.}
466
467 \wxheading{Return value}
468
469 true if the handler was found and removed, false otherwise.
470
471 \wxheading{See also}
472
473 \helpref{wxBitmapHandler}{wxbitmaphandler}
474
475 \membersection{wxBitmap::SaveFile}\label{wxbitmapsavefile}
476
477 \func{bool}{SaveFile}{\param{const wxString\& }{name}, \param{wxBitmapType}{ type}, \param{wxPalette* }{palette = NULL}}
478
479 Saves a bitmap in the named file.
480
481 \wxheading{Parameters}
482
483 \docparam{name}{A filename. The meaning of {\it name} is determined by the {\it type} parameter.}
484
485 \docparam{type}{One of the following values:
486
487 \twocolwidtha{5cm}
488 \begin{twocollist}
489 \twocolitem{{\bf wxBITMAP\_TYPE\_BMP}}{Save a Windows bitmap file.}
490 \twocolitem{{\bf wxBITMAP\_TYPE\_GIF}}{Save a GIF bitmap file.}
491 \twocolitem{{\bf wxBITMAP\_TYPE\_XBM}}{Save an X bitmap file.}
492 \twocolitem{{\bf wxBITMAP\_TYPE\_XPM}}{Save an XPM bitmap file.}
493 \end{twocollist}
494
495 The validity of these flags depends on the platform and wxWidgets configuration.
496
497 In addition, wxBitmap can save all formats that \helpref{wxImage}{wximage} can
498 (wxBITMAP\_TYPE\_JPEG, wxBITMAP\_TYPE\_PNG).
499 (Of course you must have wxImage handlers loaded.) }
500
501 \docparam{palette}{An optional palette used for saving the bitmap.}
502 % TODO: this parameter should
503 %probably be eliminated; instead the app should set the palette before saving.
504
505 \wxheading{Return value}
506
507 true if the operation succeeded, false otherwise.
508
509 \wxheading{Remarks}
510
511 Depending on how wxWidgets has been configured, not all formats may be available.
512
513 \wxheading{See also}
514
515 \helpref{wxBitmap::LoadFile}{wxbitmaploadfile}
516
517 \membersection{wxBitmap::SetDepth}\label{wxbitmapsetdepth}
518
519 \func{void}{SetDepth}{\param{int }{depth}}
520
521 Sets the depth member (does not affect the bitmap data).
522
523 \wxheading{Parameters}
524
525 \docparam{depth}{Bitmap depth.}
526
527 \membersection{wxBitmap::SetHeight}\label{wxbitmapsetheight}
528
529 \func{void}{SetHeight}{\param{int }{height}}
530
531 Sets the height member (does not affect the bitmap data).
532
533 \wxheading{Parameters}
534
535 \docparam{height}{Bitmap height in pixels.}
536
537 \membersection{wxBitmap::SetMask}\label{wxbitmapsetmask}
538
539 \func{void}{SetMask}{\param{wxMask* }{mask}}
540
541 Sets the mask for this bitmap.
542
543 \wxheading{Remarks}
544
545 The bitmap object owns the mask once this has been called.
546
547 \wxheading{See also}
548
549 \helpref{wxBitmap::GetMask}{wxbitmapgetmask}, \helpref{wxMask}{wxmask}
550
551 %% VZ: this function is an implementation detail and shouldn't be documented
552 %%\membersection{wxBitmap::SetOk}\label{wxbitmapsetok}
553 %%
554 %%\func{void}{SetOk}{\param{int }{isOk}}
555 %%
556 %%Sets the validity member (does not affect the bitmap data).
557 %%
558 %%\wxheading{Parameters}
559 %%
560 %%\docparam{isOk}{Validity flag.}
561
562 \membersection{wxBitmap::SetPalette}\label{wxbitmapsetpalette}
563
564 \func{void}{SetPalette}{\param{const wxPalette\& }{palette}}
565
566 Sets the associated palette. (Not implemented under GTK+).
567
568 \wxheading{Parameters}
569
570 \docparam{palette}{The palette to set.}
571
572 \wxheading{See also}
573
574 \helpref{wxPalette}{wxpalette}
575
576 \membersection{wxBitmap::SetWidth}\label{wxbitmapsetwidth}
577
578 \func{void}{SetWidth}{\param{int }{width}}
579
580 Sets the width member (does not affect the bitmap data).
581
582 \wxheading{Parameters}
583
584 \docparam{width}{Bitmap width in pixels.}
585
586 \membersection{wxBitmap::operator $=$}\label{wxbitmapassign}
587
588 \func{wxBitmap\& }{operator $=$}{\param{const wxBitmap\& }{bitmap}}
589
590 Assignment operator, using \helpref{reference counting}{trefcount}.
591
592 \wxheading{Parameters}
593
594 \docparam{bitmap}{Bitmap to assign.}
595
596 \wxheading{Return value}
597
598 Returns 'this' object.
599
600