Created
December 28, 2021 08:27
-
-
Save 6david9/cfb7c7f1b3c725d0a2b0bdc4e49d376d to your computer and use it in GitHub Desktop.
hello world of cairo
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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