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