Blob Blame History Raw
<!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"/>
<meta name="generator" content="Doxygen 1.8.9.1"/>
<title>cairomm: image-surface.cc</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" />
</head>
<body>
<div id="top"><!-- do not remove this div, it is closed by doxygen! -->
<div id="titlearea">
<table cellspacing="0" cellpadding="0">
 <tbody>
 <tr style="height: 56px;">
  <td style="padding-left: 0.5em;">
   <div id="projectname">cairomm
   &#160;<span id="projectnumber">1.0</span>
   </div>
  </td>
 </tr>
 </tbody>
</table>
</div>
<!-- end header part -->
<!-- Generated by Doxygen 1.8.9.1 -->
  <div id="navrow1" class="tabs">
    <ul class="tablist">
      <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><!-- top -->
<div class="header">
  <div class="headertitle">
<div class="title">image-surface.cc</div>  </div>
</div><!--header-->
<div class="contents">
<p>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 or by the ca...">Cairo::ImageSurface</a> class to render to PNG</p>
<div class="fragment"><div class="line"><span class="comment">/* M_PI is defined in math.h in the case of Microsoft Visual C++, Solaris,</span></div>
<div class="line"><span class="comment"> * et. al.</span></div>
<div class="line"><span class="comment"> */</span></div>
<div class="line"><span class="preprocessor">#if defined(_MSC_VER)</span></div>
<div class="line"><span class="preprocessor">#define _USE_MATH_DEFINES</span></div>
<div class="line"><span class="preprocessor">#endif </span></div>
<div class="line"></div>
<div class="line"><span class="preprocessor">#include &lt;string&gt;</span></div>
<div class="line"><span class="preprocessor">#include &lt;iostream&gt;</span></div>
<div class="line"><span class="preprocessor">#include &lt;cairommconfig.h&gt;</span></div>
<div class="line"><span class="preprocessor">#include &lt;cairomm/context.h&gt;</span></div>
<div class="line"><span class="preprocessor">#include &lt;cairomm/surface.h&gt;</span></div>
<div class="line"></div>
<div class="line"><span class="preprocessor">#include &lt;cmath&gt;</span></div>
<div class="line"></div>
<div class="line"><span class="keywordtype">int</span> main()</div>
<div class="line">{</div>
<div class="line">    <span class="keyword">auto</span> surface =</div>
<div class="line">        <a name="a0"></a><a class="code" href="classCairo_1_1ImageSurface.html#a82887e1a0480ab16aa891e135f2b28d6">Cairo::ImageSurface::create</a>(<a name="a1"></a><a class="code" href="namespaceCairo.html#ad3f86970e1bd354b263303c9b8759166afc97f1888578477fd656cf72d3421fbc">Cairo::FORMAT_ARGB32</a>, 600, 400);</div>
<div class="line"></div>
<div class="line">    <span class="keyword">auto</span> cr = <a name="a2"></a><a class="code" href="classCairo_1_1Context.html#a9a27f6ec57d788fd3ecbc310aeb24d99">Cairo::Context::create</a>(surface);</div>
<div class="line"></div>
<div class="line">    cr-&gt;save(); <span class="comment">// save the state of the context</span></div>
<div class="line">    cr-&gt;set_source_rgb(0.86, 0.85, 0.47);</div>
<div class="line">    cr-&gt;paint();    <span class="comment">// fill image with the color</span></div>
<div class="line">    cr-&gt;restore();  <span class="comment">// color is back to black now</span></div>
<div class="line"></div>
<div class="line">    cr-&gt;save();</div>
<div class="line">    <span class="comment">// draw a border around the image</span></div>
<div class="line">    cr-&gt;set_line_width(20.0);    <span class="comment">// make the line wider</span></div>
<div class="line">    cr-&gt;rectangle(0.0, 0.0, surface-&gt;get_width(), surface-&gt;get_height());</div>
<div class="line">    cr-&gt;stroke();</div>
<div class="line"></div>
<div class="line">    cr-&gt;set_source_rgba(0.0, 0.0, 0.0, 0.7);</div>
<div class="line">    <span class="comment">// draw a circle in the center of the image</span></div>
<div class="line">    cr-&gt;arc(surface-&gt;get_width() / 2.0, surface-&gt;get_height() / 2.0, </div>
<div class="line">            surface-&gt;get_height() / 4.0, 0.0, 2.0 * M_PI);</div>
<div class="line">    cr-&gt;stroke();</div>
<div class="line"></div>
<div class="line">    <span class="comment">// draw a diagonal line</span></div>
<div class="line">    cr-&gt;move_to(surface-&gt;get_width() / 4.0, surface-&gt;get_height() / 4.0);</div>
<div class="line">    cr-&gt;line_to(surface-&gt;get_width() * 3.0 / 4.0, surface-&gt;get_height() * 3.0 / 4.0);</div>
<div class="line">    cr-&gt;stroke();</div>
<div class="line">    cr-&gt;restore();</div>
<div class="line"></div>
<div class="line"><span class="preprocessor">#ifdef CAIRO_HAS_PNG_FUNCTIONS</span></div>
<div class="line"></div>
<div class="line">    <a name="_a3"></a><a class="codeRef" doxygen="libstdc++.tag:http://gcc.gnu.org/onlinedocs/libstdc++/latest-doxygen/" href="http://gcc.gnu.org/onlinedocs/libstdc++/latest-doxygen/a00454.html">std::string</a> filename = <span class="stringliteral">&quot;image.png&quot;</span>;</div>
<div class="line">    surface-&gt;write_to_png(filename);</div>
<div class="line"></div>
<div class="line">    <a name="a4"></a>std::cout &lt;&lt; <span class="stringliteral">&quot;Wrote png file \&quot;&quot;</span> &lt;&lt; filename &lt;&lt; <span class="stringliteral">&quot;\&quot;&quot;</span> &lt;&lt; <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/a01616.html#a8b3758bb8f17c440c7963363f42f69f3">std::endl</a>;</div>
<div class="line"></div>
<div class="line"><span class="preprocessor">#else</span></div>
<div class="line"></div>
<div class="line">    std::cout &lt;&lt; <span class="stringliteral">&quot;You must compile cairo with PNG support for this example to work.&quot;</span></div>
<div class="line">        &lt;&lt; <a class="codeRef" doxygen="libstdc++.tag:http://gcc.gnu.org/onlinedocs/libstdc++/latest-doxygen/" href="http://gcc.gnu.org/onlinedocs/libstdc++/latest-doxygen/a01616.html#a8b3758bb8f17c440c7963363f42f69f3">std::endl</a>;</div>
<div class="line"></div>
<div class="line"><span class="preprocessor">#endif</span></div>
<div class="line">}</div>
</div><!-- fragment --> </div><!-- contents -->
<!-- start footer part -->
<hr class="footer"/><address class="footer"><small>
Generated on Mon Sep 21 2015 21:56:36 for cairomm by &#160;<a href="http://www.doxygen.org/index.html">
<img class="footer" src="doxygen.png" alt="doxygen"/>
</a> 1.8.9.1
</small></address>
</body>
</html>