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