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