An example of using Cairo::ImageSurface class to render to PNG
#if defined(_MSC_VER)
#define _USE_MATH_DEFINES
#endif 
#include <string>
#include <iostream>
#include <cairommconfig.h>
#include <cairomm/context.h>
#include <cairomm/surface.h>
#include <cmath>
int main()
{
    auto surface =
    cr->save(); 
    cr->set_source_rgb(0.86, 0.85, 0.47);
    cr->paint();    
    cr->restore();  
    cr->save();
    
    cr->set_line_width(20.0);    
    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);
    
    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();
    
    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();
#ifdef CAIRO_HAS_PNG_FUNCTIONS
    surface->write_to_png(filename);
    std::cout << 
"Wrote png file \"" << filename << 
"\"" << 
std::endl;
 
#else
    std::cout << "You must compile cairo with PNG support for this example to work."
#endif
}