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
|
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=9"/>
<title>wxWidgets: Bitmaps and Icons</title>
<link href="tabs.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript" src="dynsections.js"></script>
<link href="doxygen.css" rel="stylesheet" type="text/css" />
<link href="extra_stylesheet.css" rel="stylesheet" type="text/css"/>
</head>
<body>
<div id="page_container">
<div id="top"><!-- do not remove this div, it is closed by doxygen! -->
<div id="titlearea">
<table cellspacing="0" cellpadding="0" style="width: 100%;">
<tbody>
<tr>
<td id="projectlogo">
<a href="http://www.wxwidgets.org/" target="_new">
<img alt="wxWidgets" src="logo.png"/>
</a>
</td>
<td style="padding-left: 0.5em; text-align: right;">
<span id="projectnumber">Version: 3.0.2</span>
</td>
</tr>
</tbody>
</table>
</div>
<!-- Generated by Doxygen 1.8.2 -->
<div id="navrow1" class="tabs">
<ul class="tablist">
<li><a href="index.html"><span>Main Page</span></a></li>
<li class="current"><a href="pages.html"><span>Related Pages</span></a></li>
<li><a href="modules.html"><span>Categories</span></a></li>
<li><a href="annotated.html"><span>Classes</span></a></li>
<li><a href="files.html"><span>Files</span></a></li>
</ul>
</div>
<div id="nav-path" class="navpath">
<ul>
<li class="navelem"><a class="el" href="index.html">Documentation</a></li><li class="navelem"><a class="el" href="page_topics.html">Programming Guides</a></li> </ul>
</div>
</div><!-- top -->
<div class="header">
<div class="headertitle">
<div class="title">Bitmaps and Icons </div> </div>
</div><!--header-->
<div class="contents">
<div class="toc"><h3>Table of Contents</h3>
<ul><li class="level1"><a href="#overview_bitmap_supportedformats">Supported Bitmap File Formats</a><ul><li class="level2"><a href="#overview_bitmap_supportedformats_bmp">wxBitmap</a></li>
<li class="level2"><a href="#overview_bitmap_supportedformats_icon">wxIcon</a></li>
<li class="level2"><a href="#overview_bitmap_supportedformats_cursor">wxCursor</a></li>
</ul>
</li>
<li class="level1"><a href="#overview_bitmap_handlers">Bitmap Format Handlers</a></li>
</ul>
</div>
<div class="textblock"><p>The <a class="el" href="classwx_bitmap.html" title="This class encapsulates the concept of a platform-dependent bitmap, either monochrome or colour or co...">wxBitmap</a> class encapsulates the concept of a platform-dependent bitmap, either monochrome or colour.</p>
<p>Platform-specific methods for creating a <a class="el" href="classwx_bitmap.html" title="This class encapsulates the concept of a platform-dependent bitmap, either monochrome or colour or co...">wxBitmap</a> object from an existing file are catered for, and this is an occasion where conditional compilation will sometimes be required.</p>
<p>A bitmap created dynamically or loaded from a file can be selected into a memory device context (instance of <a class="el" href="classwx_memory_d_c.html" title="A memory device context provides a means to draw graphics onto a bitmap.">wxMemoryDC</a>). This enables the bitmap to be copied to a window or memory device context using <a class="el" href="classwx_d_c.html#a12bed94a15136b9080683f4151042a34" title="Copy from a source DC to this DC.">wxDC::Blit()</a>, or to be used as a drawing surface.</p>
<p>See <a class="el" href="classwx_memory_d_c.html" title="A memory device context provides a means to draw graphics onto a bitmap.">wxMemoryDC</a> for an example of drawing onto a bitmap.</p>
<p>All wxWidgets platforms support XPMs for small bitmaps and icons. You may include the XPM inline as below, since it's C code, or you can load it at run-time.</p>
<div class="fragment"><div class="line"><span class="preprocessor">#include "sample.xpm"</span></div>
</div><!-- fragment --><p>Sometimes you wish to use a .ico resource on Windows, and XPMs on other platforms (for example to take advantage of Windows' support for multiple icon resolutions).</p>
<p>A macro, <a class="el" href="group__group__funcmacro__gdi.html#ga1f22eefa44998cbeb8f018978cf5d375" title="This macro loads an icon from either application resources (on the platforms for which they exist...">wxICON()</a>, is available which creates an icon using an XPM on the appropriate platform, or an icon resource on Windows:</p>
<div class="fragment"><div class="line"><a class="code" href="classwx_icon.html" title="An icon is a small rectangular bitmap usually used for denoting a minimized application.">wxIcon</a> icon(<a class="code" href="group__group__funcmacro__gdi.html#ga1f22eefa44998cbeb8f018978cf5d375" title="This macro loads an icon from either application resources (on the platforms for which they exist...">wxICON</a>(sample));</div>
<div class="line"></div>
<div class="line"><span class="comment">// The above line is equivalent to this:</span></div>
<div class="line"></div>
<div class="line"><span class="preprocessor">#if defined(__WXGTK__) || defined(__WXMOTIF__)</span></div>
<div class="line"><span class="preprocessor"></span> <a class="code" href="classwx_icon.html" title="An icon is a small rectangular bitmap usually used for denoting a minimized application.">wxIcon</a> icon(sample_xpm);</div>
<div class="line"><span class="preprocessor">#endif</span></div>
<div class="line"><span class="preprocessor"></span></div>
<div class="line"><span class="preprocessor">#if defined(__WXMSW__)</span></div>
<div class="line"><span class="preprocessor"></span> <a class="code" href="classwx_icon.html" title="An icon is a small rectangular bitmap usually used for denoting a minimized application.">wxIcon</a> icon(<span class="stringliteral">"sample"</span>);</div>
<div class="line"><span class="preprocessor">#endif</span></div>
</div><!-- fragment --><p>There is also a corresponding <a class="el" href="group__group__funcmacro__gdi.html#ga309f860d17c1a8c4cc54c6e772a2fd09" title="This macro loads a bitmap from either application resources (on the platforms for which they exist...">wxBITMAP()</a> macro which allows to create the bitmaps in much the same way as <a class="el" href="group__group__funcmacro__gdi.html#ga1f22eefa44998cbeb8f018978cf5d375" title="This macro loads an icon from either application resources (on the platforms for which they exist...">wxICON()</a> creates icons. It assumes that bitmaps live in resources under Windows or OS2 and XPM files under all other platforms (for XPMs, the corresponding file must be included before this macro is used, of course, and the name of the bitmap should be the same as the resource name under Windows with <code>_xpm</code> suffix). For example:</p>
<div class="fragment"><div class="line"><span class="comment">// an easy and portable way to create a bitmap</span></div>
<div class="line"><a class="code" href="classwx_bitmap.html" title="This class encapsulates the concept of a platform-dependent bitmap, either monochrome or colour or co...">wxBitmap</a> bmp(<a class="code" href="group__group__funcmacro__gdi.html#ga309f860d17c1a8c4cc54c6e772a2fd09" title="This macro loads a bitmap from either application resources (on the platforms for which they exist...">wxBITMAP</a>(bmpname));</div>
<div class="line"></div>
<div class="line"><span class="comment">// which is roughly equivalent to the following</span></div>
<div class="line"><span class="preprocessor">#if defined(__WXMSW__) || defined(__WXPM__)</span></div>
<div class="line"><span class="preprocessor"></span> <a class="code" href="classwx_bitmap.html" title="This class encapsulates the concept of a platform-dependent bitmap, either monochrome or colour or co...">wxBitmap</a> bmp(<span class="stringliteral">"bmpname"</span>, <a class="code" href="gdicmn_8h.html#a90a1eb6d85b5044a99b706fd979f27f5aa6e62442a214629e2f34c2ab71e696ff">wxBITMAP_TYPE_BMP_RESOURCE</a>);</div>
<div class="line"><span class="preprocessor">#else // Unix</span></div>
<div class="line"><span class="preprocessor"></span> <a class="code" href="classwx_bitmap.html" title="This class encapsulates the concept of a platform-dependent bitmap, either monochrome or colour or co...">wxBitmap</a> bmp(bmpname_xpm, <a class="code" href="gdicmn_8h.html#a90a1eb6d85b5044a99b706fd979f27f5a8ec4c227cd732472c3593215edd3dbf0">wxBITMAP_TYPE_XPM</a>);</div>
<div class="line"><span class="preprocessor">#endif</span></div>
</div><!-- fragment --><p>You should always use <a class="el" href="group__group__funcmacro__gdi.html#ga1f22eefa44998cbeb8f018978cf5d375" title="This macro loads an icon from either application resources (on the platforms for which they exist...">wxICON()</a> and <a class="el" href="group__group__funcmacro__gdi.html#ga309f860d17c1a8c4cc54c6e772a2fd09" title="This macro loads a bitmap from either application resources (on the platforms for which they exist...">wxBITMAP()</a> macros because they work for any platform (unlike the code above which doesn't deal with wxMac, wxX11, ...) and are shorter and more clear than versions with many <span class="literal">#ifdef</span> blocks. Alternatively, you could use the same XPMs on all platforms and avoid dealing with Windows resource files.</p>
<p>If you'd like to embed bitmaps with alpha transparency in your program, neither XPM nor BMP formats are appropriate as they don't have support for alpha and another format, typically PNG, should be used. wxWidgets provides a similar helper for PNG bitmaps called <a class="el" href="group__group__funcmacro__gdi.html#ga30fc362d22b3045f58aed54fc808f203" title="Creates a bitmap from either application resources or embedded image data in PNG format.">wxBITMAP_PNG()</a> that can be used to either load PNG files embedded in resources (meaning either Windows resource section of the executable file or OS X "Resource" subdirectory of the application bundle) or arrays containing PNG data included into the program code itself.</p>
<dl class="section see"><dt>See Also</dt><dd><a class="el" href="group__group__class__gdi.html">Graphics Device Interface (GDI)</a></dd></dl>
<h1><a class="anchor" id="overview_bitmap_supportedformats"></a>
Supported Bitmap File Formats</h1>
<p>The following lists the formats handled on different platforms. Note that missing or partially-implemented formats are automatically supplemented by using <a class="el" href="classwx_image.html" title="This class encapsulates a platform-independent image.">wxImage</a> to load the data, and then converting it to <a class="el" href="classwx_bitmap.html" title="This class encapsulates the concept of a platform-dependent bitmap, either monochrome or colour or co...">wxBitmap</a> form. Note that using <a class="el" href="classwx_image.html" title="This class encapsulates a platform-independent image.">wxImage</a> is the preferred way to load images in wxWidgets, with the exception of resources (XPM-files or native Windows resources).</p>
<p>Writing an image format handler for <a class="el" href="classwx_image.html" title="This class encapsulates a platform-independent image.">wxImage</a> is also far easier than writing one for <a class="el" href="classwx_bitmap.html" title="This class encapsulates the concept of a platform-dependent bitmap, either monochrome or colour or co...">wxBitmap</a>, because <a class="el" href="classwx_image.html" title="This class encapsulates a platform-independent image.">wxImage</a> has exactly one format on all platforms whereas <a class="el" href="classwx_bitmap.html" title="This class encapsulates the concept of a platform-dependent bitmap, either monochrome or colour or co...">wxBitmap</a> can store pixel data very differently, depending on colour depths and platform.</p>
<h2><a class="anchor" id="overview_bitmap_supportedformats_bmp"></a>
wxBitmap</h2>
<p>Under Windows, <a class="el" href="classwx_bitmap.html" title="This class encapsulates the concept of a platform-dependent bitmap, either monochrome or colour or co...">wxBitmap</a> may load the following formats: </p>
<pre class="fragment">@li Windows bitmap resource (wxBITMAP_TYPE_BMP_RESOURCE)
@li Windows bitmap file (wxBITMAP_TYPE_BMP)
@li XPM data and file (wxBITMAP_TYPE_XPM)
@li All formats that are supported by the wxImage class.
</pre><p>Under wxGTK, <a class="el" href="classwx_bitmap.html" title="This class encapsulates the concept of a platform-dependent bitmap, either monochrome or colour or co...">wxBitmap</a> may load the following formats: </p>
<pre class="fragment">@li XPM data and file (wxBITMAP_TYPE_XPM)
@li All formats that are supported by the wxImage class.
</pre><p>Under wxMotif and wxX11, <a class="el" href="classwx_bitmap.html" title="This class encapsulates the concept of a platform-dependent bitmap, either monochrome or colour or co...">wxBitmap</a> may load the following formats: </p>
<pre class="fragment">@li XBM data and file (wxBITMAP_TYPE_XBM)
@li XPM data and file (wxBITMAP_TYPE_XPM)
@li All formats that are supported by the wxImage class.
</pre><h2><a class="anchor" id="overview_bitmap_supportedformats_icon"></a>
wxIcon</h2>
<p>Under Windows, <a class="el" href="classwx_icon.html" title="An icon is a small rectangular bitmap usually used for denoting a minimized application.">wxIcon</a> may load the following formats: </p>
<pre class="fragment">@li Windows icon resource (wxBITMAP_TYPE_ICO_RESOURCE)
@li Windows icon file (wxBITMAP_TYPE_ICO)
@li XPM data and file (wxBITMAP_TYPE_XPM)
</pre><p>Under wxGTK, <a class="el" href="classwx_icon.html" title="An icon is a small rectangular bitmap usually used for denoting a minimized application.">wxIcon</a> may load the following formats: </p>
<pre class="fragment">@li XPM data and file (wxBITMAP_TYPE_XPM)
@li All formats that are supported by the wxImage class.
</pre><p>Under wxMotif and wxX11, <a class="el" href="classwx_icon.html" title="An icon is a small rectangular bitmap usually used for denoting a minimized application.">wxIcon</a> may load the following formats: </p>
<pre class="fragment">@li XBM data and file (wxBITMAP_TYPE_XBM)
@li XPM data and file (wxBITMAP_TYPE_XPM)
@li All formats that are supported by the wxImage class.
</pre><h2><a class="anchor" id="overview_bitmap_supportedformats_cursor"></a>
wxCursor</h2>
<p>Under Windows, <a class="el" href="classwx_cursor.html" title="A cursor is a small bitmap usually used for denoting where the mouse pointer is, with a picture that ...">wxCursor</a> may load the following formats: </p>
<pre class="fragment">@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)
</pre><p>Under wxGTK, <a class="el" href="classwx_cursor.html" title="A cursor is a small bitmap usually used for denoting where the mouse pointer is, with a picture that ...">wxCursor</a> may load the following formats (in addition to stock cursors): </p>
<pre class="fragment">@li None (stock cursors only).
</pre><p>Under wxMotif and wxX11, <a class="el" href="classwx_cursor.html" title="A cursor is a small bitmap usually used for denoting where the mouse pointer is, with a picture that ...">wxCursor</a> may load the following formats: </p>
<pre class="fragment">@li XBM data and file (wxBITMAP_TYPE_XBM)
</pre><h1><a class="anchor" id="overview_bitmap_handlers"></a>
Bitmap Format Handlers</h1>
<p>To provide extensibility, the functionality for loading and saving bitmap formats is not implemented in the <a class="el" href="classwx_bitmap.html" title="This class encapsulates the concept of a platform-dependent bitmap, either monochrome or colour or co...">wxBitmap</a> class, but in a number of handler classes, derived from <a class="el" href="classwx_bitmap_handler.html" title="This is the base class for implementing bitmap file loading/saving, and bitmap creation from data...">wxBitmapHandler</a>. There is a static list of handlers which <a class="el" href="classwx_bitmap.html" title="This class encapsulates the concept of a platform-dependent bitmap, either monochrome or colour or co...">wxBitmap</a> examines when a file load/save operation is requested.</p>
<p>Some handlers are provided as standard, but if you have special requirements, you may wish to initialise the <a class="el" href="classwx_bitmap.html" title="This class encapsulates the concept of a platform-dependent bitmap, either monochrome or colour or co...">wxBitmap</a> class with some extra handlers which you write yourself or receive from a third party.</p>
<p>To add a handler object to <a class="el" href="classwx_bitmap.html" title="This class encapsulates the concept of a platform-dependent bitmap, either monochrome or colour or co...">wxBitmap</a>, your application needs to include the header which implements it, and then call the static function <a class="el" href="classwx_bitmap.html#a6418825ad15574229188e0c5f97a4f3a" title="Adds a handler to the end of the static list of format handlers.">wxBitmap::AddHandler()</a>.</p>
<dl class="section note"><dt>Note</dt><dd>Bitmap handlers are not implemented on all platforms, and new ones rarely need to be implemented since <a class="el" href="classwx_image.html" title="This class encapsulates a platform-independent image.">wxImage</a> can be used for loading most formats, as noted earlier. </dd></dl>
</div></div><!-- contents -->
<address class="footer">
<small>
Generated on Thu Nov 27 2014 13:46:42 for wxWidgets by <a href="http://www.doxygen.org/index.html" target="_new">Doxygen</a> 1.8.2
</small>
</address>
<script src="wxwidgets.js" type="text/javascript"></script>
</div><!-- #page_container -->
</body>
</html>
|