]> git.saurik.com Git - wxWidgets.git/blame - docs/latex/wx/tbitmap.tex
* Fixed a bug in notebook.tex
[wxWidgets.git] / docs / latex / wx / tbitmap.tex
CommitLineData
a660d684
KB
1\section{Bitmaps 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
fe604ccd 13enables the bitmap to be copied to a window or memory device context
a660d684
KB
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
fe604ccd 17version of the graphic which appears on the main window.
a660d684
KB
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 in X and in Windows 3. The alternative is to use the string
23version of the bitmap constructor, which loads a file under X and a
24resource under Windows 3, but has the disadvantage of requiring the
25X icon file to be available at run-time.
26
27\begin{verbatim}
28#ifdef wx_x
29#include "aiai.xbm"
30#endif
31#ifdef wx_msw
32 wxIcon *icon = new wxBitmap("aiai");
33#endif
34#ifdef wx_x
35 wxIcon *icon = new wxBitmap(aiai_bits, aiai_width, aiai_height);
36#endif
37\end{verbatim}
38
39\subsection{Loading bitmaps: further information}
40
41There is provision for a number of bitmap
42formats via the standard wxBitmap class. These facilities can
43be enabled or disabled using settings in wx\_setup.h.
44
45XPM colour pixmaps may be loaded and saved under Windows and X, with
46some restrictions imposed by the lack of colourmap facility when
47using XPM files. The user may elect to use XPM files as a cross-platform
48stabdard, or translate between XPM and BMP files using a suitable
49utility.
50
51Also, under Windows, DIBs (device independent bitmaps with extension BMP)
52may be dynamically loaded and saved. Under X, GIF and BMP files may be
53loaded but not saved.
54
55\subsection{Bitmap format handlers}
56
57To provide extensibility, the functionality for loading and saving bitmap formats
58is not implemented in the wxBitmap class, but in a number of handler classes,
59derived from wxBitmapHandler. There is a static list of handlers which wxBitmap
60examines when a file load/save operation is requested. Some handlers are provided as standard, but if you
61have special requirements, you may wish to initialise the wxBitmap class with
62some extra handlers which you write yourself or receive from a third party.
63
64To add a handler object to wxBitmap, your application needs to include the header which implements it, and
65then call the static function \helpref{wxBitmap::AddHandler}{wxbitmapaddhandler}. For example:
66
67{\small
68\begin{verbatim}
69 #include "JPEGBitmapHandler.h"
70 ...
71 // Initialisation
72 wxBitmap::AddHandler(new wxJPEGBitmapHandler);
73 ...
74\end{verbatim}
75}
76
77Assuming wxJPEGBitmapHandler has been written correctly, you should now be able to load and save JPEG files
78using the usual wxBitmap API.
79
80To see how bitmap handlers are implemented, please look at the files {\tt bitmap.h} and {\tt bitmap.cpp}.
81
82\subsection{wxIcon overview}\label{wxiconoverview}
83
84TODO.
85