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