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