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
|
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html;charset=iso-8859-1">
<title>cairomm: image-surface.cc</title>
<link href="cairomm.css" rel="stylesheet" type="text/css">
</head>
<body>
<!-- Generated by Doxygen 1.5.9 -->
<div class="navigation" id="top">
<div class="tabs">
<ul>
<li><a href="index.html"><span>Main Page</span></a></li>
<li><a href="pages.html"><span>Related Pages</span></a></li>
<li><a href="namespaces.html"><span>Namespaces</span></a></li>
<li><a href="annotated.html"><span>Classes</span></a></li>
<li><a href="examples.html"><span>Examples</span></a></li>
</ul>
</div>
</div>
<div class="contents">
<h1>image-surface.cc</h1>An example of using <a class="el" href="classCairo_1_1ImageSurface.html" title="Image surfaces provide the ability to render to memory buffers either allocated by...">Cairo::ImageSurface</a> class to render to PNG<p>
<div class="fragment"><pre class="fragment"><span class="preprocessor">#include <<a class="codeRef" doxygen="libstdc++.tag:http://gcc.gnu.org/onlinedocs/libstdc++/latest-doxygen/" href="http://gcc.gnu.org/onlinedocs/libstdc++/latest-doxygen/a00906.html">string</a>></span>
<span class="preprocessor">#include <<a class="codeRef" doxygen="libstdc++.tag:http://gcc.gnu.org/onlinedocs/libstdc++/latest-doxygen/" href="http://gcc.gnu.org/onlinedocs/libstdc++/latest-doxygen/a00777.html">iostream</a>></span>
<span class="preprocessor">#include <cairommconfig.h></span>
<span class="preprocessor">#include <cairomm/context.h></span>
<span class="preprocessor">#include <cairomm/surface.h></span>
<span class="comment">/* M_PI is defined in math.h in the case of Microsoft Visual C++, Solaris,</span>
<span class="comment"> * et. al.</span>
<span class="comment"> */</span>
<span class="preprocessor">#if defined(_MSC_VER)</span>
<span class="preprocessor"></span><span class="preprocessor">#define _USE_MATH_DEFINES</span>
<span class="preprocessor"></span><span class="preprocessor">#endif </span>
<span class="preprocessor"></span>
<span class="preprocessor">#include <<a class="codeRef" doxygen="libstdc++.tag:http://gcc.gnu.org/onlinedocs/libstdc++/latest-doxygen/" href="http://gcc.gnu.org/onlinedocs/libstdc++/latest-doxygen/a00667.html">cmath</a>></span>
<span class="keywordtype">int</span> main()
{
<a name="_a0"></a><a class="code" href="classCairo_1_1RefPtr.html" title="RefPtr&lt;&gt; is a reference-counting shared smartpointer.">Cairo::RefPtr<Cairo::ImageSurface></a> surface =
<a name="a1"></a><a class="code" href="classCairo_1_1ImageSurface.html#82887e1a0480ab16aa891e135f2b28d6" title="Creates an image surface of the specified format and dimensions.">Cairo::ImageSurface::create</a>(<a name="a2"></a><a class="code" href="namespaceCairo.html#d3f86970e1bd354b263303c9b8759166fc97f1888578477fd656cf72d3421fbc">Cairo::FORMAT_ARGB32</a>, 600, 400);
<a class="code" href="classCairo_1_1RefPtr.html" title="RefPtr&lt;&gt; is a reference-counting shared smartpointer.">Cairo::RefPtr<Cairo::Context></a> cr = <a name="a3"></a><a class="code" href="classCairo_1_1Context.html#9a27f6ec57d788fd3ecbc310aeb24d99">Cairo::Context::create</a>(surface);
cr->save(); <span class="comment">// save the state of the context</span>
cr->set_source_rgb(0.86, 0.85, 0.47);
cr->paint(); <span class="comment">// fill image with the color</span>
cr->restore(); <span class="comment">// color is back to black now</span>
cr->save();
<span class="comment">// draw a border around the image</span>
cr->set_line_width(20.0); <span class="comment">// make the line wider</span>
cr->rectangle(0.0, 0.0, surface->get_width(), surface->get_height());
cr->stroke();
cr->set_source_rgba(0.0, 0.0, 0.0, 0.7);
<span class="comment">// draw a circle in the center of the image</span>
cr->arc(surface->get_width() / 2.0, surface->get_height() / 2.0,
surface->get_height() / 4.0, 0.0, 2.0 * M_PI);
cr->stroke();
<span class="comment">// draw a diagonal line</span>
cr->move_to(surface->get_width() / 4.0, surface->get_height() / 4.0);
cr->line_to(surface->get_width() * 3.0 / 4.0, surface->get_height() * 3.0 / 4.0);
cr->stroke();
cr->restore();
<span class="preprocessor">#ifdef CAIRO_HAS_PNG_FUNCTIONS</span>
<span class="preprocessor"></span>
<a name="_a4"></a><a class="codeRef" doxygen="libstdc++.tag:http://gcc.gnu.org/onlinedocs/libstdc++/latest-doxygen/" href="http://gcc.gnu.org/onlinedocs/libstdc++/latest-doxygen/a00218.html">std::string</a> filename = <span class="stringliteral">"image.png"</span>;
surface->write_to_png(filename);
<a name="a5"></a><a class="codeRef" doxygen="libstdc++.tag:http://gcc.gnu.org/onlinedocs/libstdc++/latest-doxygen/" href="http://gcc.gnu.org/onlinedocs/libstdc++/latest-doxygen/a00969.html#af93fdf0812752e0e02c501dea1b38f0">std::cout</a> << <span class="stringliteral">"Wrote png file \""</span> << filename << <span class="stringliteral">"\""</span> << <a name="a6"></a><a class="codeRef" doxygen="libstdc++.tag:http://gcc.gnu.org/onlinedocs/libstdc++/latest-doxygen/" href="http://gcc.gnu.org/onlinedocs/libstdc++/latest-doxygen/a00969.html#9e2ba1ed9813a1f03adc9a87dbf491a5">std::endl</a>;
<span class="preprocessor">#else</span>
<span class="preprocessor"></span>
<a class="codeRef" doxygen="libstdc++.tag:http://gcc.gnu.org/onlinedocs/libstdc++/latest-doxygen/" href="http://gcc.gnu.org/onlinedocs/libstdc++/latest-doxygen/a00969.html#af93fdf0812752e0e02c501dea1b38f0">std::cout</a> << <span class="stringliteral">"You must compile cairo with PNG support for this example to work."</span>
<< std::endl;
<span class="preprocessor">#endif</span>
<span class="preprocessor"></span>}
</pre></div> </div>
<hr size="1"><address style="text-align: right;"><small>Generated on Thu Aug 13 11:40:12 2009 for cairomm by 
<a href="http://www.doxygen.org/index.html">
<img src="doxygen.png" alt="doxygen" align="middle" border="0"></a> 1.5.9 </small></address>
</body>
</html>
|