Sophie

Sophie

distrib > Fedora > 13 > x86_64 > by-pkgid > f5b8bf9ba5c3c0062e8b494b5ddab2e8 > files > 158

cairomm-devel-1.8.4-1.fc13.i686.rpm

<!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&#160;Page</span></a></li>
      <li><a href="pages.html"><span>Related&#160;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 &lt;<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>&gt;</span>
<span class="preprocessor">#include &lt;<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>&gt;</span>
<span class="preprocessor">#include &lt;cairommconfig.h&gt;</span>
<span class="preprocessor">#include &lt;cairomm/context.h&gt;</span>
<span class="preprocessor">#include &lt;cairomm/surface.h&gt;</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 &lt;<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>&gt;</span>

<span class="keywordtype">int</span> main()
{
    <a name="_a0"></a><a class="code" href="classCairo_1_1RefPtr.html" title="RefPtr&amp;lt;&amp;gt; is a reference-counting shared smartpointer.">Cairo::RefPtr&lt;Cairo::ImageSurface&gt;</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&amp;lt;&amp;gt; is a reference-counting shared smartpointer.">Cairo::RefPtr&lt;Cairo::Context&gt;</a> cr = <a name="a3"></a><a class="code" href="classCairo_1_1Context.html#9a27f6ec57d788fd3ecbc310aeb24d99">Cairo::Context::create</a>(surface);

    cr-&gt;save(); <span class="comment">// save the state of the context</span>
    cr-&gt;set_source_rgb(0.86, 0.85, 0.47);
    cr-&gt;paint();    <span class="comment">// fill image with the color</span>
    cr-&gt;restore();  <span class="comment">// color is back to black now</span>

    cr-&gt;save();
    <span class="comment">// draw a border around the image</span>
    cr-&gt;set_line_width(20.0);    <span class="comment">// make the line wider</span>
    cr-&gt;rectangle(0.0, 0.0, surface-&gt;get_width(), surface-&gt;get_height());
    cr-&gt;stroke();

    cr-&gt;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-&gt;arc(surface-&gt;get_width() / 2.0, surface-&gt;get_height() / 2.0, 
            surface-&gt;get_height() / 4.0, 0.0, 2.0 * M_PI);
    cr-&gt;stroke();

    <span class="comment">// draw a diagonal line</span>
    cr-&gt;move_to(surface-&gt;get_width() / 4.0, surface-&gt;get_height() / 4.0);
    cr-&gt;line_to(surface-&gt;get_width() * 3.0 / 4.0, surface-&gt;get_height() * 3.0 / 4.0);
    cr-&gt;stroke();
    cr-&gt;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-&gt;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> &lt;&lt; <span class="stringliteral">"Wrote png file \""</span> &lt;&lt; filename &lt;&lt; <span class="stringliteral">"\""</span> &lt;&lt; <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> &lt;&lt; <span class="stringliteral">"You must compile cairo with PNG support for this example to work."</span>
        &lt;&lt; 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&#160;
<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>