]> git.saurik.com Git - wxWidgets.git/blame_incremental - docs/latex/wx/bitmap.tex
added wxTB_HORZ_TEXT (patch 713813); documented it; moved toolbar styles to toolbar.h
[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.
7
8\wxheading{Derived from}
9
10\helpref{wxGDIObject}{wxgdiobject}\\
11\helpref{wxObject}{wxobject}
12
13\wxheading{Include file}
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{wxbitmapconstr}
34
35\func{}{wxBitmap}{\void}
36
37Default constructor.
38
39\func{}{wxBitmap}{\param{const wxBitmap\& }{bitmap}}
40
41Copy constructor.
42
43\func{}{wxBitmap}{\param{void*}{ data}, \param{int}{ type}, \param{int}{ width}, \param{int}{ height}, \param{int}{ depth = -1}}
44
45Creates a bitmap from the given data which is interpreted in platform-dependent
46manner.
47
48\func{}{wxBitmap}{\param{const char}{ bits[]}, \param{int}{ width}, \param{int}{ height}\\
49 \param{int}{ depth = 1}}
50
51Creates a bitmap from an array of bits.
52
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
58data is passed without any changes to the underlying {\tt CreateBitmap()} API.
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.
62
63\func{}{wxBitmap}{\param{int}{ width}, \param{int}{ height}, \param{int}{ depth = -1}}
64
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.
68
69\func{}{wxBitmap}{\param{const char**}{ bits}}
70
71Creates a bitmap from XPM data.
72
73\func{}{wxBitmap}{\param{const wxString\& }{name}, \param{long}{ type}}
74
75Loads a bitmap from a file or resource.
76
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.
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
83to take place.
84
85When in 8-bit mode (PseudoColour mode), the GTK port will use a color cube created
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
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.
106Its meaning is determined by the {\it type} parameter.}
107
108\docparam{type}{May be one of the following:
109
110\twocolwidtha{5cm}
111\begin{twocollist}
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.}
118\end{twocollist}
119
120The validity of these flags depends on the platform and wxWindows configuration.
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.
123Under wxMotif, the available formats are XBM data, XBM file, XPM data, XPM file.
124
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,
127and wxBITMAP\_TYPE\_PNM. Of course, you must have wxImage handlers loaded. }
128
129\docparam{img}{Platform-independent wxImage object.}
130
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.
167Under X, {\it type} defaults to wxBITMAP\_TYPE\_XPM.
168
169\wxheading{See also}
170
171\helpref{wxBitmap::LoadFile}{wxbitmaploadfile}
172
173\pythonnote{Constructors supported by wxPython are:\par
174\indented{2cm}{\begin{twocollist}
175\twocolitem{{\bf wxBitmap(name, flag)}}{Loads a bitmap from a file}
176\twocolitem{{\bf wxEmptyBitmap(width, height, depth = -1)}}{Creates an
177empty bitmap with the given specifications}
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.}
185\end{twocollist}}
186}
187
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\item{Wx::Bitmap->newFromBits( bits, width, height, depth = 1 )}
194\item{Wx::Bitmap->newFromXPM( data )}
195\end{itemize}
196}
197
198\membersection{wxBitmap::\destruct{wxBitmap}}
199
200\func{}{\destruct{wxBitmap}}{\void}
201
202Destroys the wxBitmap object and possibly the underlying bitmap data.
203Because reference counting is used, the bitmap may not actually be
204destroyed at this point - only when the reference count is zero will the
205data be deleted.
206
207If the application omits to delete the bitmap explicitly, the bitmap will be
208destroyed automatically by wxWindows when the application exits.
209
210Do not delete a bitmap that is selected into a memory device context.
211
212\membersection{wxBitmap::AddHandler}\label{wxbitmapaddhandler}
213
214\func{static void}{AddHandler}{\param{wxBitmapHandler*}{ handler}}
215
216Adds a handler to the end of the static list of format handlers.
217
218\docparam{handler}{A new bitmap format handler object. There is usually only one instance
219of a given handler class in an application session.}
220
221\wxheading{See also}
222
223\helpref{wxBitmapHandler}{wxbitmaphandler}
224
225\membersection{wxBitmap::CleanUpHandlers}
226
227\func{static void}{CleanUpHandlers}{\void}
228
229Deletes all bitmap handlers.
230
231This function is called by wxWindows on exit.
232
233\membersection{wxBitmap::ConvertToImage}\label{wxbitmapconverttoimage}
234
235\func{wxImage}{ConvertToImage}{\void}
236
237Creates an image from a platform-dependent bitmap. This preserves
238mask information so that bitmaps and images can be converted back
239and forth without loss in that respect.
240
241\membersection{wxBitmap::CopyFromIcon}\label{wxbitmapcopyfromicon}
242
243\func{bool}{CopyFromIcon}{\param{const wxIcon\&}{ icon}}
244
245Creates the bitmap from an icon.
246
247\membersection{wxBitmap::Create}\label{wxbitmapcreate}
248
249\func{virtual bool}{Create}{\param{int}{ width}, \param{int}{ height}, \param{int}{ depth = -1}}
250
251Creates a fresh bitmap. If the final argument is omitted, the display depth of
252the screen is used.
253
254\func{virtual bool}{Create}{\param{void*}{ data}, \param{int}{ type}, \param{int}{ width}, \param{int}{ height}, \param{int}{ depth = -1}}
255
256Creates a bitmap from the given data, which can be of arbitrary type.
257
258\wxheading{Parameters}
259
260\docparam{width}{The width of the bitmap in pixels.}
261
262\docparam{height}{The height of the bitmap in pixels.}
263
264\docparam{depth}{The depth of the bitmap in pixels. If this is -1, the screen depth is used.}
265
266\docparam{data}{Data whose type depends on the value of {\it type}.}
267
268\docparam{type}{A bitmap type identifier - see \helpref{wxBitmap::wxBitmap}{wxbitmapconstr} for a list
269of possible values.}
270
271\wxheading{Return value}
272
273true if the call succeeded, false otherwise.
274
275\wxheading{Remarks}
276
277The first form works on all platforms. The portability of the second form depends on the
278type of data.
279
280\wxheading{See also}
281
282\helpref{wxBitmap::wxBitmap}{wxbitmapconstr}
283
284\membersection{wxBitmap::FindHandler}
285
286\func{static wxBitmapHandler*}{FindHandler}{\param{const wxString\& }{name}}
287
288Finds the handler with the given name.
289
290\func{static wxBitmapHandler*}{FindHandler}{\param{const wxString\& }{extension}, \param{long}{ bitmapType}}
291
292Finds the handler associated with the given extension and type.
293
294\func{static wxBitmapHandler*}{FindHandler}{\param{long }{bitmapType}}
295
296Finds the handler associated with the given bitmap type.
297
298\docparam{name}{The handler name.}
299
300\docparam{extension}{The file extension, such as ``bmp".}
301
302\docparam{bitmapType}{The bitmap type, such as wxBITMAP\_TYPE\_BMP.}
303
304\wxheading{Return value}
305
306A pointer to the handler if found, NULL otherwise.
307
308\wxheading{See also}
309
310\helpref{wxBitmapHandler}{wxbitmaphandler}
311
312\membersection{wxBitmap::GetDepth}
313
314\constfunc{int}{GetDepth}{\void}
315
316Gets the colour depth of the bitmap. A value of 1 indicates a
317monochrome bitmap.
318
319\membersection{wxBitmap::GetHandlers}
320
321\func{static wxList\&}{GetHandlers}{\void}
322
323Returns the static list of bitmap format handlers.
324
325\wxheading{See also}
326
327\helpref{wxBitmapHandler}{wxbitmaphandler}
328
329\membersection{wxBitmap::GetHeight}\label{wxbitmapgetheight}
330
331\constfunc{int}{GetHeight}{\void}
332
333Gets the height of the bitmap in pixels.
334
335\membersection{wxBitmap::GetPalette}\label{wxbitmapgetpalette}
336
337\constfunc{wxPalette*}{GetPalette}{\void}
338
339Gets the associated palette (if any) which may have been loaded from a file
340or set for the bitmap.
341
342\wxheading{See also}
343
344\helpref{wxPalette}{wxpalette}
345
346\membersection{wxBitmap::GetMask}\label{wxbitmapgetmask}
347
348\constfunc{wxMask*}{GetMask}{\void}
349
350Gets the associated mask (if any) which may have been loaded from a file
351or set for the bitmap.
352
353\wxheading{See also}
354
355\helpref{wxBitmap::SetMask}{wxbitmapsetmask}, \helpref{wxMask}{wxmask}
356
357\membersection{wxBitmap::GetWidth}\label{wxbitmapgetwidth}
358
359\constfunc{int}{GetWidth}{\void}
360
361Gets the width of the bitmap in pixels.
362
363\wxheading{See also}
364
365\helpref{wxBitmap::GetHeight}{wxbitmapgetheight}
366
367\membersection{wxBitmap::GetSubBitmap}\label{wxbitmapgetsubbitmap}
368
369\constfunc{wxBitmap}{GetSubBitmap}{\param{const wxRect\&}{rect}}
370
371Returns a sub bitmap of the current one as long as the rect belongs entirely to
372the bitmap. This function preserves bit depth and mask information.
373
374\membersection{wxBitmap::InitStandardHandlers}
375
376\func{static void}{InitStandardHandlers}{\void}
377
378Adds the standard bitmap format handlers, which, depending on wxWindows
379configuration, can be handlers for Windows bitmap, Windows bitmap resource, and XPM.
380
381This function is called by wxWindows on startup.
382
383\wxheading{See also}
384
385\helpref{wxBitmapHandler}{wxbitmaphandler}
386
387\membersection{wxBitmap::InsertHandler}
388
389\func{static void}{InsertHandler}{\param{wxBitmapHandler*}{ handler}}
390
391Adds a handler at the start of the static list of format handlers.
392
393\docparam{handler}{A new bitmap format handler object. There is usually only one instance
394of a given handler class in an application session.}
395
396\wxheading{See also}
397
398\helpref{wxBitmapHandler}{wxbitmaphandler}
399
400\membersection{wxBitmap::LoadFile}\label{wxbitmaploadfile}
401
402\func{bool}{LoadFile}{\param{const wxString\&}{ name}, \param{long}{ type}}
403
404Loads a bitmap from a file or resource.
405
406\wxheading{Parameters}
407
408\docparam{name}{Either a filename or a Windows resource name.
409The meaning of {\it name} is determined by the {\it type} parameter.}
410
411\docparam{type}{One of the following values:
412
413\twocolwidtha{5cm}
414\begin{twocollist}
415\twocolitem{{\bf wxBITMAP\_TYPE\_BMP}}{Load a Windows bitmap file.}
416\twocolitem{{\bf wxBITMAP\_TYPE\_BMP\_RESOURCE}}{Load a Windows bitmap from the resource database.}
417\twocolitem{{\bf wxBITMAP\_TYPE\_GIF}}{Load a GIF bitmap file.}
418\twocolitem{{\bf wxBITMAP\_TYPE\_XBM}}{Load an X bitmap file.}
419\twocolitem{{\bf wxBITMAP\_TYPE\_XPM}}{Load an XPM bitmap file.}
420\end{twocollist}
421
422The validity of these flags depends on the platform and wxWindows configuration.
423
424In addition, wxBitmap can read all formats that \helpref{wxImage}{wximage} can
425(wxBITMAP\_TYPE\_JPEG, wxBITMAP\_TYPE\_PNG, wxBITMAP\_TYPE\_GIF, wxBITMAP\_TYPE\_PCX, wxBITMAP\_TYPE\_PNM).
426(Of course you must have wxImage handlers loaded.) }
427
428\wxheading{Return value}
429
430true if the operation succeeded, false otherwise.
431
432\wxheading{Remarks}
433
434A palette may be associated with the bitmap if one exists (especially for
435colour Windows bitmaps), and if the code supports it. You can check
436if one has been created by using the \helpref{GetPalette}{wxbitmapgetpalette} member.
437
438\wxheading{See also}
439
440\helpref{wxBitmap::SaveFile}{wxbitmapsavefile}
441
442\membersection{wxBitmap::Ok}\label{wxbitmapok}
443
444\constfunc{bool}{Ok}{\void}
445
446Returns true if bitmap data is present.
447
448\membersection{wxBitmap::RemoveHandler}
449
450\func{static bool}{RemoveHandler}{\param{const wxString\& }{name}}
451
452Finds the handler with the given name, and removes it. The handler
453is not deleted.
454
455\docparam{name}{The handler name.}
456
457\wxheading{Return value}
458
459true if the handler was found and removed, false otherwise.
460
461\wxheading{See also}
462
463\helpref{wxBitmapHandler}{wxbitmaphandler}
464
465\membersection{wxBitmap::SaveFile}\label{wxbitmapsavefile}
466
467\func{bool}{SaveFile}{\param{const wxString\& }{name}, \param{int}{ type}, \param{wxPalette* }{palette = NULL}}
468
469Saves a bitmap in the named file.
470
471\wxheading{Parameters}
472
473\docparam{name}{A filename. The meaning of {\it name} is determined by the {\it type} parameter.}
474
475\docparam{type}{One of the following values:
476
477\twocolwidtha{5cm}
478\begin{twocollist}
479\twocolitem{{\bf wxBITMAP\_TYPE\_BMP}}{Save a Windows bitmap file.}
480\twocolitem{{\bf wxBITMAP\_TYPE\_GIF}}{Save a GIF bitmap file.}
481\twocolitem{{\bf wxBITMAP\_TYPE\_XBM}}{Save an X bitmap file.}
482\twocolitem{{\bf wxBITMAP\_TYPE\_XPM}}{Save an XPM bitmap file.}
483\end{twocollist}
484
485The validity of these flags depends on the platform and wxWindows configuration.
486
487In addition, wxBitmap can save all formats that \helpref{wxImage}{wximage} can
488(wxBITMAP\_TYPE\_JPEG, wxBITMAP\_TYPE\_PNG).
489(Of course you must have wxImage handlers loaded.) }
490
491\docparam{palette}{An optional palette used for saving the bitmap.}
492% TODO: this parameter should
493%probably be eliminated; instead the app should set the palette before saving.
494
495\wxheading{Return value}
496
497true if the operation succeeded, false otherwise.
498
499\wxheading{Remarks}
500
501Depending on how wxWindows has been configured, not all formats may be available.
502
503\wxheading{See also}
504
505\helpref{wxBitmap::LoadFile}{wxbitmaploadfile}
506
507\membersection{wxBitmap::SetDepth}\label{wxbitmapsetdepth}
508
509\func{void}{SetDepth}{\param{int }{depth}}
510
511Sets the depth member (does not affect the bitmap data).
512
513\wxheading{Parameters}
514
515\docparam{depth}{Bitmap depth.}
516
517\membersection{wxBitmap::SetHeight}\label{wxbitmapsetheight}
518
519\func{void}{SetHeight}{\param{int }{height}}
520
521Sets the height member (does not affect the bitmap data).
522
523\wxheading{Parameters}
524
525\docparam{height}{Bitmap height in pixels.}
526
527\membersection{wxBitmap::SetMask}\label{wxbitmapsetmask}
528
529\func{void}{SetMask}{\param{wxMask* }{mask}}
530
531Sets the mask for this bitmap.
532
533\wxheading{Remarks}
534
535The bitmap object owns the mask once this has been called.
536
537\wxheading{See also}
538
539\helpref{wxBitmap::GetMask}{wxbitmapgetmask}, \helpref{wxMask}{wxmask}
540
541%% VZ: this function is an implementation detail and shouldn't be documented
542%%\membersection{wxBitmap::SetOk}
543%%
544%%\func{void}{SetOk}{\param{int }{isOk}}
545%%
546%%Sets the validity member (does not affect the bitmap data).
547%%
548%%\wxheading{Parameters}
549%%
550%%\docparam{isOk}{Validity flag.}
551
552\membersection{wxBitmap::SetPalette}\label{wxbitmapsetpalette}
553
554\func{void}{SetPalette}{\param{const wxPalette\& }{palette}}
555
556Sets the associated palette.
557
558\wxheading{Parameters}
559
560\docparam{palette}{The palette to set.}
561
562\wxheading{See also}
563
564\helpref{wxPalette}{wxpalette}
565
566\membersection{wxBitmap::SetWidth}
567
568\func{void}{SetWidth}{\param{int }{width}}
569
570Sets the width member (does not affect the bitmap data).
571
572\wxheading{Parameters}
573
574\docparam{width}{Bitmap width in pixels.}
575
576\membersection{wxBitmap::operator $=$}
577
578\func{wxBitmap\& }{operator $=$}{\param{const wxBitmap\& }{bitmap}}
579
580Assignment operator. This operator does not copy any data, but instead
581passes a pointer to the data in {\it bitmap} and increments a reference
582counter. It is a fast operation.
583
584\wxheading{Parameters}
585
586\docparam{bitmap}{Bitmap to assign.}
587
588\wxheading{Return value}
589
590Returns 'this' object.
591
592\membersection{wxBitmap::operator $==$}
593
594\func{bool}{operator $==$}{\param{const wxBitmap\& }{bitmap}}
595
596Equality operator. This operator tests whether the internal data pointers are
597equal (a fast test).
598
599\wxheading{Parameters}
600
601\docparam{bitmap}{Bitmap to compare with 'this'}
602
603\wxheading{Return value}
604
605Returns true if the bitmaps were effectively equal, false otherwise.
606
607\membersection{wxBitmap::operator $!=$}
608
609\func{bool}{operator $!=$}{\param{const wxBitmap\& }{bitmap}}
610
611Inequality operator. This operator tests whether the internal data pointers are
612unequal (a fast test).
613
614\wxheading{Parameters}
615
616\docparam{bitmap}{Bitmap to compare with 'this'}
617
618\wxheading{Return value}
619
620Returns true if the bitmaps were unequal, false otherwise.
621