File: wx284.htm

package info (click to toggle)
wxwin2-doc 2.01-1
  • links: PTS
  • area: main
  • in suites: potato
  • size: 6,540 kB
  • ctags: 5,968
  • sloc: cpp: 15,157; makefile: 434; sh: 6
file content (163 lines) | stat: -rw-r--r-- 6,263 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
<HTML>
<head><title>Bitmaps and icons overview</title></head>

<BODY BGCOLOR=#FFFFFF>
<A NAME="wxbitmapoverview"></A><CENTER>
<A HREF="wx.htm"><img align=center src="contents.gif" BORDER=0 ALT="Contents"></A> <A HREF="wx278.htm#overviews"><img align=center src="up.gif" BORDER=0 ALT="Up"></A> <A HREF="wx283.htm#wxconfigoverview"><img align=center src="back.gif" BORDER=0 ALT="Previous"></A> <A HREF="wx285.htm#wxdialogoverview"><img align=center src="forward.gif" BORDER=0 ALT="Next"></A> </CENTER><HR>

<H2>Bitmaps and icons overview</H2>
<P>
Classes: <A HREF="wx32.htm#wxbitmap">wxBitmap</A>, <A HREF="wx33.htm#wxbitmaphandler">wxBitmapHandler</A>, <A HREF="wx114.htm#wxicon">wxIcon</A>, <A HREF="wx59.htm#wxcursor">wxCursor</A>.<P>
The wxBitmap class encapsulates the concept of a platform-dependent bitmap,
either monochrome or colour. Platform-specific methods for creating a
wxBitmap object from an existing file are catered for, and
this is an occasion where conditional compilation will sometimes be
required.<P>
A bitmap created dynamically or loaded from a file can be selected
into a memory device context (instance of <A HREF="wx137.htm#wxmemorydc">wxMemoryDC</A>). This
enables the bitmap to be copied to a window or memory device context
using <A HREF="wx65.htm#wxdcblit">wxDC::Blit</A>, or to be used as a drawing surface.  The <B>
wxToolBarSimple</B> class is implemented using bitmaps, and the toolbar demo
shows one of the toolbar bitmaps being used for drawing a miniature
version of the graphic which appears on the main window.<P>
See <A HREF="wx137.htm#wxmemorydc">wxMemoryDC</A> for an example of drawing onto a bitmap.<P>
The following shows the conditional compilation required to load a
bitmap under Unix and in Windows. The alternative is to use the string
version of the bitmap constructor, which loads a file under Unix and a
resource or file under Windows, but has the disadvantage of requiring the
XPM icon file to be available at run-time.<P>
<PRE>
#if defined(__WXGTK__) || defined(__WXMOTIF__)
#include "mondrian.xpm"
#endif
</PRE>
A macro, wxICON, is available which creates an icon using an XPM
on the appropriate platform, or an icon resource on Windows.<P>
<PRE>
wxIcon icon(wxICON(mondrian));

// Equivalent to:

#if defined(__WXGTK__) || defined(__WXMOTIF__)
wxIcon icon(mondrian_xpm);
#endif

#if defined(__WXMSW__)
wxIcon icon("mondrian");
#endif
</PRE>
<A HREF="#supportedbitmapformats">Supported bitmap file formats</A><BR>
<A HREF="#bitmaphandlers">Bitmap format handlers</A><BR>
<P>

<HR>
<A NAME="supportedbitmapformats"></A>
<H3>Supported bitmap file formats</H3>
<P>
The following lists the formats handled on different platforms. Note
that missing or partially-implemented formats can be supplemented
by using <A HREF="wx115.htm#wximage">wxImage</A> to load the data, and then converting
it to wxBitmap form.<P>
<B><FONT COLOR="#FF0000">wxBitmap</FONT></B><P>
Under Windows, wxBitmap may load the following formats:<P>
<UL>

<LI> Windows bitmap resource (wxBITMAP_TYPE_BMP_RESOURCE)
<LI> Windows bitmap file (wxBITMAP_TYPE_BMP)
<LI> PNG file (wxBITMAP_TYPE_PNG). Currently 4-bit (16-colour) PNG files do not load properly.
<LI> XPM data and file (wxBITMAP_TYPE_XPM)
</UL>
<P>
Under wxGTK, wxBitmap may load the following formats:<P>
<UL>

<LI> Windows bitmap file (wxBITMAP_TYPE_BMP)
<LI> PNG (wxBITMAP_TYPE_PNG).
<LI> XPM data and file (wxBITMAP_TYPE_XPM)
</UL>
<P>
Under wxMotif, wxBitmap may load the following formats:<P>
<UL>

<LI> XBM data and file (wxBITMAP_TYPE_XBM)
<LI> XPM data and file (wxBITMAP_TYPE_XPM)
</UL>
<P>
<B><FONT COLOR="#FF0000">wxIcon</FONT></B><P>
Under Windows, wxIcon may load the following formats:<P>
<UL>

<LI> Windows icon resource (wxBITMAP_TYPE_ICO_RESOURCE)
<LI> Windows icon file (wxBITMAP_TYPE_ICO)
<LI> XPM data and file (wxBITMAP_TYPE_XPM)
</UL>
<P>
Under wxGTK, wxIcon may load the following formats:<P>
<UL>

<LI> PNG (wxBITMAP_TYPE_PNG).
<LI> XPM data and file (wxBITMAP_TYPE_XPM)
</UL>
<P>
Under wxMotif, wxIcon may load the following formats:<P>
<UL>

<LI> XBM data and file (wxBITMAP_TYPE_XBM)
<LI> XPM data and file (wxBITMAP_TYPE_XPM)
</UL>
<P>
<B><FONT COLOR="#FF0000">wxCursor</FONT></B><P>
Under Windows, wxCursor may load the following formats:<P>
<UL>

<LI> Windows cursor resource (wxBITMAP_TYPE_CUR_RESOURCE)
<LI> Windows cursor file (wxBITMAP_TYPE_CUR)
<LI> Windows icon file (wxBITMAP_TYPE_ICO)
<LI> Windows bitmap file (wxBITMAP_TYPE_BMP)
</UL>
<P>
Under wxGTK, wxCursor may load the following formats (in additional
to stock cursors):<P>
<UL>

<LI> None (stock cursors only).
</UL>
<P>
Under wxMotif, wxCursor may load the following formats:<P>
<UL>

<LI> XBM data and file (wxBITMAP_TYPE_XBM)
</UL>
<P>

<HR>
<A NAME="bitmaphandlers"></A>
<H3>Bitmap format handlers</H3>
<P>
To provide extensibility, the functionality for loading and saving bitmap formats
is not implemented in the wxBitmap class, but in a number of handler classes,
derived from wxBitmapHandler. There is a static list of handlers which wxBitmap
examines when a file load/save operation is requested. Some handlers are provided as standard, but if you
have special requirements, you may wish to initialise the wxBitmap class with
some extra handlers which you write yourself or receive from a third party.<P>
To add a handler object to wxBitmap, your application needs to include the header which implements it, and
then call the static function <A HREF="wx32.htm#wxbitmapaddhandler">wxBitmap::AddHandler</A>. For example:<P>
<FONT SIZE=2>
<PRE>
  #include &lt;wx/pnghand.h&gt;
  #include &lt;wx/xpmhand.h&gt;
  ...
  // Initialisation
  wxBitmap::AddHandler(new wxPNGFileHandler);
  wxBitmap::AddHandler(new wxXPMFileHandler);
  wxBitmap::AddHandler(new wxXPMDataHandler);
  ...
</PRE>
</FONT><P>
Assuming the handlers have been written correctly, you should now be able to load and save PNG files
and XPM files using the usual wxBitmap API.<P>
<B>Note:</B> bitmap handlers are not implemented on all platforms. Currently, the above is only necessary on
Windows, to save the extra overhead of formats that may not be necessary (if you don't use them, they
are not linked into the executable). Unix platforms have PNG and XPM capability built-in (where supported).<P>

</BODY></HTML>