<!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
 <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 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><!-- 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 <string></span></div>
<div class="line"><span class="preprocessor">#include <iostream></span></div>
<div class="line"><span class="preprocessor">#include <cairommconfig.h></span></div>
<div class="line"><span class="preprocessor">#include <cairomm/context.h></span></div>
<div class="line"><span class="preprocessor">#include <cairomm/surface.h></span></div>
<div class="line"></div>
<div class="line"><span class="preprocessor">#include <cmath></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->save(); <span class="comment">// save the state of the context</span></div>
<div class="line"> cr->set_source_rgb(0.86, 0.85, 0.47);</div>
<div class="line"> cr->paint(); <span class="comment">// fill image with the color</span></div>
<div class="line"> cr->restore(); <span class="comment">// color is back to black now</span></div>
<div class="line"></div>
<div class="line"> cr->save();</div>
<div class="line"> <span class="comment">// draw a border around the image</span></div>
<div class="line"> cr->set_line_width(20.0); <span class="comment">// make the line wider</span></div>
<div class="line"> cr->rectangle(0.0, 0.0, surface->get_width(), surface->get_height());</div>
<div class="line"> cr->stroke();</div>
<div class="line"></div>
<div class="line"> cr->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->arc(surface->get_width() / 2.0, surface->get_height() / 2.0, </div>
<div class="line"> surface->get_height() / 4.0, 0.0, 2.0 * M_PI);</div>
<div class="line"> cr->stroke();</div>
<div class="line"></div>
<div class="line"> <span class="comment">// draw a diagonal line</span></div>
<div class="line"> cr->move_to(surface->get_width() / 4.0, surface->get_height() / 4.0);</div>
<div class="line"> cr->line_to(surface->get_width() * 3.0 / 4.0, surface->get_height() * 3.0 / 4.0);</div>
<div class="line"> cr->stroke();</div>
<div class="line"> cr->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">"image.png"</span>;</div>
<div class="line"> surface->write_to_png(filename);</div>
<div class="line"></div>
<div class="line"> <a name="a4"></a>std::cout << <span class="stringliteral">"Wrote png file \""</span> << filename << <span class="stringliteral">"\""</span> << <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 << <span class="stringliteral">"You must compile cairo with PNG support for this example to work."</span></div>
<div class="line"> << <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  <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>