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