1 \section{Bitmaps and icons overview
}\label{wxbitmapoverview
}
3 Classes:
\helpref{wxBitmap
}{wxbitmap
},
\helpref{wxBitmapHandler
}{wxbitmaphandler
},
\helpref{wxIcon
}{wxicon
},
\helpref{wxCursor
}{wxcursor
}.
5 The wxBitmap class encapsulates the concept of a platform-dependent bitmap,
6 either monochrome or colour. Platform-specific methods for creating a
7 wxBitmap object from an existing file are catered for, and
8 this is an occasion where conditional compilation will sometimes be
11 A bitmap created dynamically or loaded from a file can be selected
12 into a memory device context (instance of
\helpref{wxMemoryDC
}{wxmemorydc
}). This
13 enables the bitmap to be copied to a window or memory device context
14 using
\helpref{wxDC::Blit
}{wxdcblit
}, or to be used as a drawing surface. The
{\bf
15 wxToolBarSimple
} class is implemented using bitmaps, and the toolbar demo
16 shows one of the toolbar bitmaps being used for drawing a miniature
17 version of the graphic which appears on the main window.
19 See
\helpref{wxMemoryDC
}{wxmemorydc
} for an example of drawing onto a bitmap.
21 The following shows the conditional compilation required to load a
22 bitmap under Unix and in Windows. The alternative is to use the string
23 version of the bitmap constructor, which loads a file under Unix and a
24 resource or file under Windows, but has the disadvantage of requiring the
25 XPM icon file to be available at run-time.
28 #if defined(__WXGTK__) || defined(__WXMOTIF__)
29 #include "mondrian.xpm"
33 A macro, wxICON, is available which creates an icon using an XPM
34 on the appropriate platform, or an icon resource on Windows.
37 wxIcon icon(wxICON(mondrian));
41 #if defined(__WXGTK__) || defined(__WXMOTIF__)
42 wxIcon icon(mondrian_xpm);
45 #if defined(__WXMSW__)
46 wxIcon icon("mondrian");
50 \subsection{Supported bitmap file formats
}\label{supportedbitmapformats
}
52 The following lists the formats handled on different platforms. Note
53 that missing or partially-implemented formats can be supplemented
54 by using
\helpref{wxImage
}{wximage
} to load the data, and then converting
59 Under Windows, wxBitmap may load the following formats:
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)
68 Under wxGTK, wxBitmap may load the following formats:
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)
76 Under wxMotif, wxBitmap may load the following formats:
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)
87 Under Windows, wxIcon may load the following formats:
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)
95 Under wxGTK, wxIcon may load the following formats:
97 \begin{itemize
}\itemsep=
0pt
98 \item PNG (wxBITMAP
\_TYPE\_PNG).
99 \item XPM data and file (wxBITMAP
\_TYPE\_XPM)
102 Under wxMotif, wxIcon may load the following formats:
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)
113 Under Windows, wxCursor may load the following formats:
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)
122 Under wxGTK, wxCursor may load the following formats (in additional
125 \begin{itemize
}\itemsep=
0pt
126 \item None (stock cursors only).
129 Under wxMotif, wxCursor may load the following formats:
131 \begin{itemize
}\itemsep=
0pt
132 \item XBM data and file (wxBITMAP
\_TYPE\_XBM)
135 \subsection{Bitmap format handlers
}\label{bitmaphandlers
}
137 To provide extensibility, the functionality for loading and saving bitmap formats
138 is not implemented in the wxBitmap class, but in a number of handler classes,
139 derived from wxBitmapHandler. There is a static list of handlers which wxBitmap
140 examines when a file load/save operation is requested. Some handlers are provided as standard, but if you
141 have special requirements, you may wish to initialise the wxBitmap class with
142 some extra handlers which you write yourself or receive from a third party.
144 To add a handler object to wxBitmap, your application needs to include the header which implements it, and
145 then call the static function
\helpref{wxBitmap::AddHandler
}{wxbitmapaddhandler
}. For example:
149 #include <wx/pnghand.h>
150 #include <wx/xpmhand.h>
153 wxBitmap::AddHandler(new wxPNGFileHandler);
154 wxBitmap::AddHandler(new wxXPMFileHandler);
155 wxBitmap::AddHandler(new wxXPMDataHandler);
160 Assuming the handlers have been written correctly, you should now be able to load and save PNG files
161 and XPM files using the usual wxBitmap API.
163 {\bf Note:
} bitmap handlers are not implemented on all platforms. Currently, the above is only necessary on
164 Windows, to save the extra overhead of formats that may not be necessary (if you don't use them, they
165 are not linked into the executable). Unix platforms have PNG and XPM capability built-in (where supported).