Skip to content

Instantly share code, notes, and snippets.

@6david9
Created December 28, 2021 08:27
Show Gist options
  • Save 6david9/cfb7c7f1b3c725d0a2b0bdc4e49d376d to your computer and use it in GitHub Desktop.
Save 6david9/cfb7c7f1b3c725d0a2b0bdc4e49d376d to your computer and use it in GitHub Desktop.
hello world of cairo
#include <iostream>
#include <cairo/cairo.h>
#include <cairo/cairo-quartz.h>
int main(int argc, const char * argv[]) {
cairo_surface_t *surface = cairo_quartz_surface_create(CAIRO_FORMAT_RGB24, 320 * 3.0, 560 * 3.0);
cairo_t *cr = cairo_create(surface);
cairo_set_antialias(cr, CAIRO_ANTIALIAS_BEST);
cairo_save(cr);
cairo_set_source_rgb (cr, 1.0, 0.0, 0.0);
cairo_paint(cr);
cairo_restore(cr);
cairo_save(cr);
cairo_set_line_width(cr, 1.0);
cairo_set_source_rgb(cr, 0.0, 0.0, 1.0);
cairo_move_to(cr, 0.0, 0.0);
cairo_line_to(cr, 320.0 * 3.0, 560.0 * 3.0);
cairo_stroke(cr);
cairo_restore(cr);
cairo_status_t status = cairo_surface_write_to_png(surface, "/Users/name/Desktop/a.png");
cairo_surface_destroy(surface);
cairo_destroy(cr);
if (status) {
std::cout << "error: " << status << std::endl;
return 1;
}
std::cout << "done" << std::endl;
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment