]> git.saurik.com Git - wxWidgets.git/blame_incremental - docs/latex/wx/tbitmap.tex
Added dcbase target to various makefiles
[wxWidgets.git] / docs / latex / wx / tbitmap.tex
... / ...
CommitLineData
1\section{Bitmaps and icons overview}\label{wxbitmapoverview}
2
3Classes: \helpref{wxBitmap}{wxbitmap}, \helpref{wxBitmapHandler}{wxbitmaphandler}, \helpref{wxIcon}{wxicon}, \helpref{wxCursor}{wxcursor}.
4
5The wxBitmap class encapsulates the concept of a platform-dependent bitmap,
6either monochrome or colour. Platform-specific methods for creating a
7wxBitmap object from an existing file are catered for, and
8this is an occasion where conditional compilation will sometimes be
9required.
10
11A bitmap created dynamically or loaded from a file can be selected
12into a memory device context (instance of \helpref{wxMemoryDC}{wxmemorydc}). This
13enables the bitmap to be copied to a window or memory device context
14using \helpref{wxDC::Blit}{wxdcblit}, or to be used as a drawing surface. The {\bf
15wxToolBarSimple} class is implemented using bitmaps, and the toolbar demo
16shows one of the toolbar bitmaps being used for drawing a miniature
17version of the graphic which appears on the main window.
18
19See \helpref{wxMemoryDC}{wxmemorydc} for an example of drawing onto a bitmap.
20
21The following shows the conditional compilation required to load a
22bitmap under Unix and in Windows. The alternative is to use the string
23version of the bitmap constructor, which loads a file under Unix and a
24resource or file under Windows, but has the disadvantage of requiring the
25XPM icon file to be available at run-time.
26
27\begin{verbatim}
28#if defined(__WXGTK__) || defined(__WXMOTIF__)
29#include "mondrian.xpm"
30#endif
31\end{verbatim}
32
33A macro, wxICON, is available which creates an icon using an XPM
34on the appropriate platform, or an icon resource on Windows.
35
36\begin{verbatim}
37wxIcon icon(wxICON(mondrian));
38
39// Equivalent to:
40
41#if defined(__WXGTK__) || defined(__WXMOTIF__)
42wxIcon icon(mondrian_xpm);
43#endif
44
45#if defined(__WXMSW__)
46wxIcon icon("mondrian");
47#endif
48\end{verbatim}
49
50\subsection{Supported bitmap file formats}\label{supportedbitmapformats}
51
52The following lists the formats handled on different platforms. Note
53that missing or partially-implemented formats can be supplemented
54by using \helpref{wxImage}{wximage} to load the data, and then converting
55it to wxBitmap form.
56
57\wxheading{wxBitmap}
58
59Under Windows, wxBitmap may load the following formats:
60
61\begin{itemize}\itemsep=0pt
62\item Windows bitmap resource (wxBITMAP\_TYPE\_BMP\_RESOURCE)
63\item Windows bitmap file (wxBITMAP\_TYPE\_BMP)
64\item PNG file (wxBITMAP\_TYPE\_PNG). Currently 4-bit (16-colour) PNG files do not load properly.
65\item XPM data and file (wxBITMAP\_TYPE\_XPM)
66\end{itemize}
67
68Under wxGTK, wxBitmap may load the following formats:
69
70\begin{itemize}\itemsep=0pt
71\item Windows bitmap file (wxBITMAP\_TYPE\_BMP)
72\item PNG (wxBITMAP\_TYPE\_PNG).
73\item XPM data and file (wxBITMAP\_TYPE\_XPM)
74\end{itemize}
75
76Under wxMotif, wxBitmap may load the following formats:
77
78\begin{itemize}\itemsep=0pt
79%\item Windows bitmap file (wxBITMAP\_TYPE\_BMP)
80%\item PNG (wxBITMAP\_TYPE\_PNG).
81\item XBM data and file (wxBITMAP\_TYPE\_XBM)
82\item XPM data and file (wxBITMAP\_TYPE\_XPM)
83\end{itemize}
84
85\wxheading{wxIcon}
86
87Under Windows, wxIcon may load the following formats:
88
89\begin{itemize}\itemsep=0pt
90\item Windows icon resource (wxBITMAP\_TYPE\_ICO\_RESOURCE)
91\item Windows icon file (wxBITMAP\_TYPE\_ICO)
92\item XPM data and file (wxBITMAP\_TYPE\_XPM)
93\end{itemize}
94
95Under wxGTK, wxIcon may load the following formats:
96
97\begin{itemize}\itemsep=0pt
98\item PNG (wxBITMAP\_TYPE\_PNG).
99\item XPM data and file (wxBITMAP\_TYPE\_XPM)
100\end{itemize}
101
102Under wxMotif, wxIcon may load the following formats:
103
104\begin{itemize}\itemsep=0pt
105%\item Windows bitmap file (wxBITMAP\_TYPE\_BMP)
106%\item PNG (wxBITMAP\_TYPE\_PNG).
107\item XBM data and file (wxBITMAP\_TYPE\_XBM)
108\item XPM data and file (wxBITMAP\_TYPE\_XPM)
109\end{itemize}
110
111\wxheading{wxCursor}
112
113Under Windows, wxCursor may load the following formats:
114
115\begin{itemize}\itemsep=0pt
116\item Windows cursor resource (wxBITMAP\_TYPE\_CUR\_RESOURCE)
117\item Windows cursor file (wxBITMAP\_TYPE\_CUR)
118\item Windows icon file (wxBITMAP\_TYPE\_ICO)
119\item Windows bitmap file (wxBITMAP\_TYPE\_BMP)
120\end{itemize}
121
122Under wxGTK, wxCursor may load the following formats (in additional
123to stock cursors):
124
125\begin{itemize}\itemsep=0pt
126\item None (stock cursors only).
127\end{itemize}
128
129Under wxMotif, wxCursor may load the following formats:
130
131\begin{itemize}\itemsep=0pt
132\item XBM data and file (wxBITMAP\_TYPE\_XBM)
133\end{itemize}
134
135\subsection{Bitmap format handlers}\label{bitmaphandlers}
136
137To provide extensibility, the functionality for loading and saving bitmap formats
138is not implemented in the wxBitmap class, but in a number of handler classes,
139derived from wxBitmapHandler. There is a static list of handlers which wxBitmap
140examines when a file load/save operation is requested. Some handlers are provided as standard, but if you
141have special requirements, you may wish to initialise the wxBitmap class with
142some extra handlers which you write yourself or receive from a third party.
143
144To add a handler object to wxBitmap, your application needs to include the header which implements it, and
145then call the static function \helpref{wxBitmap::AddHandler}{wxbitmapaddhandler}. For example:
146
147{\small
148\begin{verbatim}
149 #include <wx/pnghand.h>
150 #include <wx/xpmhand.h>
151 ...
152 // Initialisation
153 wxBitmap::AddHandler(new wxPNGFileHandler);
154 wxBitmap::AddHandler(new wxXPMFileHandler);
155 wxBitmap::AddHandler(new wxXPMDataHandler);
156 ...
157\end{verbatim}
158}
159
160Assuming the handlers have been written correctly, you should now be able to load and save PNG files
161and XPM files using the usual wxBitmap API.
162
163{\bf Note:} bitmap handlers are not implemented on all platforms. Currently, the above is only necessary on
164Windows, to save the extra overhead of formats that may not be necessary (if you don't use them, they
165are not linked into the executable). Unix platforms have PNG and XPM capability built-in (where supported).
166