]> git.saurik.com Git - wxWidgets.git/blame - docs/doxygen/overviews/bitmap.h
Add "inherit" to <font> XRC tag.
[wxWidgets.git] / docs / doxygen / overviews / bitmap.h
CommitLineData
15b6757b 1/////////////////////////////////////////////////////////////////////////////
e0a47918 2// Name: bitmap.h
15b6757b
FM
3// Purpose: topic overview
4// Author: wxWidgets team
5// RCS-ID: $Id$
526954c5 6// Licence: wxWindows licence
15b6757b
FM
7/////////////////////////////////////////////////////////////////////////////
8
880efa2a 9/**
36c9828f 10
880efa2a 11@page overview_bitmap Bitmaps and Icons
36c9828f 12
880efa2a
BP
13Classes:
14@li wxBitmap
15@li wxBitmapHandler
16@li wxIcon
17@li wxCursor
59c0db6a 18
880efa2a
BP
19The wxBitmap class encapsulates the concept of a platform-dependent bitmap,
20either monochrome or colour. Platform-specific methods for creating a wxBitmap
21object from an existing file are catered for, and this is an occasion where
22conditional compilation will sometimes be required.
59c0db6a 23
880efa2a
BP
24A bitmap created dynamically or loaded from a file can be selected into a
25memory device context (instance of wxMemoryDC). This enables the bitmap to be
26copied to a window or memory device context using wxDC::Blit(), or to be used
27as a drawing surface.
59c0db6a 28
880efa2a 29See wxMemoryDC for an example of drawing onto a bitmap.
59c0db6a 30
880efa2a
BP
31All wxWidgets platforms support XPMs for small bitmaps and icons. You may
32include the XPM inline as below, since it's C code, or you can load it at
33run-time.
36c9828f 34
880efa2a 35@code
3cb332c1 36#include "sample.xpm"
880efa2a 37@endcode
36c9828f 38
880efa2a
BP
39Sometimes you wish to use a .ico resource on Windows, and XPMs on other
40platforms (for example to take advantage of Windows' support for multiple icon
41resolutions).
59c0db6a 42
880efa2a
BP
43A macro, wxICON(), is available which creates an icon using an XPM on the
44appropriate platform, or an icon resource on Windows:
36c9828f 45
880efa2a 46@code
3cb332c1 47wxIcon icon(wxICON(sample));
36c9828f 48
880efa2a 49// The above line is equivalent to this:
36c9828f 50
880efa2a 51#if defined(__WXGTK__) || defined(__WXMOTIF__)
3cb332c1 52 wxIcon icon(sample_xpm);
880efa2a 53#endif
36c9828f 54
880efa2a 55#if defined(__WXMSW__)
3cb332c1 56 wxIcon icon("sample");
880efa2a
BP
57#endif
58@endcode
36c9828f 59
880efa2a
BP
60There is also a corresponding wxBITMAP() macro which allows to create the
61bitmaps in much the same way as wxICON() creates icons. It assumes that bitmaps
62live in resources under Windows or OS2 and XPM files under all other platforms
63(for XPMs, the corresponding file must be included before this macro is used,
64of course, and the name of the bitmap should be the same as the resource name
65under Windows with @c _xpm suffix). For example:
36c9828f 66
880efa2a
BP
67@code
68// an easy and portable way to create a bitmap
69wxBitmap bmp(wxBITMAP(bmpname));
36c9828f 70
880efa2a
BP
71// which is roughly equivalent to the following
72#if defined(__WXMSW__) || defined(__WXPM__)
4ca8531f 73 wxBitmap bmp("bmpname", wxBITMAP_TYPE_BMP_RESOURCE);
880efa2a
BP
74#else // Unix
75 wxBitmap bmp(bmpname_xpm, wxBITMAP_TYPE_XPM);
76#endif
77@endcode
36c9828f 78
880efa2a
BP
79You should always use wxICON() and wxBITMAP() macros because they work for any
80platform (unlike the code above which doesn't deal with wxMac, wxX11, ...) and
c3f641cb
VZ
81are shorter and more clear than versions with many @ifdef_ blocks.
82Alternatively, you could use the same XPMs on all platforms and avoid dealing
83with Windows resource files.
84
85If you'd like to embed bitmaps with alpha transparency in your program, neither
86XPM nor BMP formats are appropriate as they don't have support for alpha and
87another format, typically PNG, should be used. wxWidgets provides a similar
88helper for PNG bitmaps called wxBITMAP_PNG() that can be used to either load
89PNG files embedded in resources (meaning either Windows resource section of the
90executable file or OS X "Resource" subdirectory of the application bundle) or
91arrays containing PNG data included into the program code itself.
36c9828f 92
880efa2a
BP
93@li @ref overview_bitmap_supportedformats
94@li @ref overview_bitmap_handlers
59c0db6a
FM
95
96
880efa2a 97<hr>
36c9828f 98
59c0db6a 99
880efa2a 100@section overview_bitmap_supportedformats Supported Bitmap File Formats
36c9828f 101
880efa2a
BP
102The following lists the formats handled on different platforms. Note that
103missing or partially-implemented formats are automatically supplemented by
104using wxImage to load the data, and then converting it to wxBitmap form. Note
105that using wxImage is the preferred way to load images in wxWidgets, with the
106exception of resources (XPM-files or native Windows resources).
36c9828f 107
880efa2a
BP
108Writing an image format handler for wxImage is also far easier than writing one
109for wxBitmap, because wxImage has exactly one format on all platforms whereas
110wxBitmap can store pixel data very differently, depending on colour depths and
111platform.
36c9828f 112
880efa2a 113@subsection overview_bitmap_supportedformats_bmp wxBitmap
98ba1eee 114
880efa2a 115Under Windows, wxBitmap may load the following formats:
36c9828f 116
880efa2a
BP
117 @li Windows bitmap resource (wxBITMAP_TYPE_BMP_RESOURCE)
118 @li Windows bitmap file (wxBITMAP_TYPE_BMP)
119 @li XPM data and file (wxBITMAP_TYPE_XPM)
120 @li All formats that are supported by the wxImage class.
36c9828f 121
880efa2a 122Under wxGTK, wxBitmap may load the following formats:
36c9828f 123
880efa2a
BP
124 @li XPM data and file (wxBITMAP_TYPE_XPM)
125 @li All formats that are supported by the wxImage class.
36c9828f 126
880efa2a 127Under wxMotif and wxX11, wxBitmap may load the following formats:
36c9828f 128
880efa2a
BP
129 @li XBM data and file (wxBITMAP_TYPE_XBM)
130 @li XPM data and file (wxBITMAP_TYPE_XPM)
131 @li All formats that are supported by the wxImage class.
98ba1eee 132
880efa2a 133@subsection overview_bitmap_supportedformats_icon wxIcon
36c9828f 134
880efa2a 135Under Windows, wxIcon may load the following formats:
36c9828f 136
880efa2a
BP
137 @li Windows icon resource (wxBITMAP_TYPE_ICO_RESOURCE)
138 @li Windows icon file (wxBITMAP_TYPE_ICO)
139 @li XPM data and file (wxBITMAP_TYPE_XPM)
36c9828f 140
880efa2a 141Under wxGTK, wxIcon may load the following formats:
36c9828f 142
880efa2a
BP
143 @li XPM data and file (wxBITMAP_TYPE_XPM)
144 @li All formats that are supported by the wxImage class.
36c9828f 145
880efa2a 146Under wxMotif and wxX11, wxIcon may load the following formats:
36c9828f 147
880efa2a
BP
148 @li XBM data and file (wxBITMAP_TYPE_XBM)
149 @li XPM data and file (wxBITMAP_TYPE_XPM)
150 @li All formats that are supported by the wxImage class.
36c9828f 151
880efa2a 152@subsection overview_bitmap_supportedformats_cursor wxCursor
98ba1eee 153
880efa2a 154Under Windows, wxCursor may load the following formats:
36c9828f 155
880efa2a
BP
156 @li Windows cursor resource (wxBITMAP_TYPE_CUR_RESOURCE)
157 @li Windows cursor file (wxBITMAP_TYPE_CUR)
158 @li Windows icon file (wxBITMAP_TYPE_ICO)
159 @li Windows bitmap file (wxBITMAP_TYPE_BMP)
36c9828f 160
880efa2a
BP
161Under wxGTK, wxCursor may load the following formats (in addition to stock
162cursors):
36c9828f 163
880efa2a 164 @li None (stock cursors only).
36c9828f 165
880efa2a 166Under wxMotif and wxX11, wxCursor may load the following formats:
36c9828f 167
880efa2a 168 @li XBM data and file (wxBITMAP_TYPE_XBM)
36c9828f 169
36c9828f 170
880efa2a 171@section overview_bitmap_handlers Bitmap Format Handlers
36c9828f 172
880efa2a
BP
173To provide extensibility, the functionality for loading and saving bitmap
174formats is not implemented in the wxBitmap class, but in a number of handler
175classes, derived from wxBitmapHandler. There is a static list of handlers which
176wxBitmap examines when a file load/save operation is requested.
36c9828f 177
880efa2a
BP
178Some handlers are provided as standard, but if you have special requirements,
179you may wish to initialise the wxBitmap class with some extra handlers which
180you write yourself or receive from a third party.
36c9828f 181
880efa2a
BP
182To add a handler object to wxBitmap, your application needs to include the
183header which implements it, and then call the static function
184wxBitmap::AddHandler().
36c9828f 185
880efa2a
BP
186@note Bitmap handlers are not implemented on all platforms, and new ones rarely
187need to be implemented since wxImage can be used for loading most formats, as
188noted earlier.
36c9828f 189
e0a47918 190*/
36c9828f 191