Blame docs/reference/html/image-surface_8cc-example.html

Packit 908522
Packit 908522
<html xmlns="http://www.w3.org/1999/xhtml">
Packit 908522
<head>
Packit 908522
<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
Packit 908522
<meta http-equiv="X-UA-Compatible" content="IE=9"/>
Packit 908522
<meta name="generator" content="Doxygen 1.8.9.1"/>
Packit 908522
<title>cairomm: image-surface.cc</title>
Packit 908522
<link href="tabs.css" rel="stylesheet" type="text/css"/>
Packit 908522
<script type="text/javascript" src="jquery.js"></script>
Packit 908522
<script type="text/javascript" src="dynsections.js"></script>
Packit 908522
<link href="doxygen.css" rel="stylesheet" type="text/css" />
Packit 908522
</head>
Packit 908522
<body>
Packit 908522
Packit 908522
Packit 908522
Packit 908522
 
Packit 908522
 
Packit 908522
  
Packit 908522
   
cairomm
Packit 908522
    1.0
Packit 908522
   
Packit 908522
  
Packit 908522
 
Packit 908522
 
Packit 908522
Packit 908522
Packit 908522
Packit 908522
Packit 908522
  
Packit 908522
    
    Packit 908522
          
  • Main Page
  • Packit 908522
          
  • Related Pages
  • Packit 908522
          
  • Namespaces
  • Packit 908522
          
  • Classes
  • Packit 908522
          
  • Examples
  • Packit 908522
        
    Packit 908522
      
    Packit 908522
    Packit 908522
    Packit 908522
      
    Packit 908522
    image-surface.cc
    Packit 908522
    Packit 908522
    Packit 908522

    An example of using Cairo::ImageSurface class to render to PNG

    Packit 908522
    /* M_PI is defined in math.h in the case of Microsoft Visual C++, Solaris,
    Packit 908522
    * et. al.
    Packit 908522
    */
    Packit 908522
    #if defined(_MSC_VER)
    Packit 908522
    #define _USE_MATH_DEFINES
    Packit 908522
    #endif
    Packit 908522
    Packit 908522
    #include <string>
    Packit 908522
    #include <iostream>
    Packit 908522
    #include <cairommconfig.h>
    Packit 908522
    #include <cairomm/context.h>
    Packit 908522
    #include <cairomm/surface.h>
    Packit 908522
    Packit 908522
    #include <cmath>
    Packit 908522
    Packit 908522
    int main()
    Packit 908522
    {
    Packit 908522
    auto surface =
    Packit 908522
    Packit 908522
    Packit 908522
    auto cr = Cairo::Context::create(surface);
    Packit 908522
    Packit 908522
    cr->save(); // save the state of the context
    Packit 908522
    cr->set_source_rgb(0.86, 0.85, 0.47);
    Packit 908522
    cr->paint(); // fill image with the color
    Packit 908522
    cr->restore(); // color is back to black now
    Packit 908522
    Packit 908522
    cr->save();
    Packit 908522
    // draw a border around the image
    Packit 908522
    cr->set_line_width(20.0); // make the line wider
    Packit 908522
    cr->rectangle(0.0, 0.0, surface->get_width(), surface->get_height());
    Packit 908522
    cr->stroke();
    Packit 908522
    Packit 908522
    cr->set_source_rgba(0.0, 0.0, 0.0, 0.7);
    Packit 908522
    // draw a circle in the center of the image
    Packit 908522
    cr->arc(surface->get_width() / 2.0, surface->get_height() / 2.0,
    Packit 908522
    surface->get_height() / 4.0, 0.0, 2.0 * M_PI);
    Packit 908522
    cr->stroke();
    Packit 908522
    Packit 908522
    // draw a diagonal line
    Packit 908522
    cr->move_to(surface->get_width() / 4.0, surface->get_height() / 4.0);
    Packit 908522
    cr->line_to(surface->get_width() * 3.0 / 4.0, surface->get_height() * 3.0 / 4.0);
    Packit 908522
    cr->stroke();
    Packit 908522
    cr->restore();
    Packit 908522
    Packit 908522
    #ifdef CAIRO_HAS_PNG_FUNCTIONS
    Packit 908522
    Packit 908522
    std::string filename = "image.png";
    Packit 908522
    surface->write_to_png(filename);
    Packit 908522
    Packit 908522
    std::cout << "Wrote png file \"" << filename << "\"" << std::endl;
    Packit 908522
    Packit 908522
    #else
    Packit 908522
    Packit 908522
    std::cout << "You must compile cairo with PNG support for this example to work."
    Packit 908522
    Packit 908522
    Packit 908522
    #endif
    Packit 908522
    }
    Packit 908522
     
    Packit 908522
    Packit 908522

    <address class="footer"><small>
    Packit 908522
    Generated on Mon Sep 21 2015 21:56:36 for cairomm by  
    Packit 908522
    doxygen
    Packit 908522
     1.8.9.1
    Packit 908522
    </small></address>
    Packit 908522
    </body>
    Packit 908522
    </html>