int main() { double xc = 128.0; double yc = 128.0; double radius = 100.0; double angle1 = 45.0 * (M_PI/180.0); /* angles are specified */ double angle2 = 180.0 * (M_PI/180.0); /* in radians */ cairo_surface_t *surface = cairo_image_surface_create (CAIRO_FORMAT_ARGB32, 400, 400); cairo_t *cr = cairo_create (surface); cairo_set_line_width (cr, 10.0); cairo_arc (cr, xc, yc, radius, angle1, angle2); cairo_stroke (cr); /* draw helping lines */ cairo_set_source_rgba (cr, 1, 0.2, 0.2, 0.6); cairo_set_line_width (cr, 6.0); cairo_arc (cr, xc, yc, 10.0, 0, 2*M_PI); cairo_fill (cr); cairo_arc (cr, xc, yc, radius, angle1, angle1); cairo_line_to (cr, xc, yc); cairo_arc (cr, xc, yc, radius, angle2, angle2); cairo_line_to (cr, xc, yc); cairo_stroke (cr); cairo_destroy (cr); cairo_surface_write_to_png (surface, OUTFILE); fprintf(stderr,"wrote " OUTFILE "\n"); cairo_surface_destroy (surface); return 0; }
int main(void) { int width, height; width = 640; height = 480; cairo_surface_t *surface; cairo_t *cr; surface = cairo_image_surface_create(CAIRO_FORMAT_ARGB32, width, height); cr = cairo_create(surface); cairo_set_line_width(cr, 10); cairo_set_source_rgb(cr, 0.8, 0.2, 0); /* 将坐标原点移至中心 */ cairo_translate(cr, width / 2, height / 2); cairo_arc(cr, 0, 0, 50, 0, 2 * M_PI); cairo_stroke_preserve(cr); cairo_set_source_rgb(cr, 0.3, 0.4, 0.6); cairo_fill(cr); cairo_surface_write_to_png(surface, "circle.png"); cairo_destroy(cr); cairo_surface_destroy(surface); return 0; }
int main (int argc, char *argv[]) { cairo_surface_t *surface = //Sets the Cairo surface context cairo_image_surface_create (CAIRO_FORMAT_ARGB32, 421, 410); //Creates Cairo image surface, sets image resolution. cairo_t *cr = //Declare *cr as a Cairo context. cairo_create (surface); //Sets the Cairo context as a pointer, *cr. /* Second triangle */ cairo_set_source_rgba (cr, 0.60, 0.85, 0.91, 0.8); //Sets the color of the triangle. cairo_line_to (cr, 275, 44); //Draws a line from Point A to Point B. cairo_line_to (cr, 377, 102); //Draws a line from Point B to Point C. cairo_line_to (cr, 100, 118); //Draws a line from Point C back to Point A. cairo_close_path (cr); //Finishes the connections between Points A and C, closes off the figure. cairo_fill_preserve (cr); //Preserve fill so shape doesn't output as an outline. cairo_set_source_rgba (cr, 0.60, 0.85, 0.91, 0.8); //Sets the color of the triangle (again) cairo_stroke (cr); //Draw the final shape /* Write output and clean up */ cairo_surface_write_to_png (surface, "../images/triangle2-color.png"); //Name the resulting image as triangle2-color.png cairo_destroy (cr); //Destroy the context pointer, frees up memory and/or lag cairo_surface_destroy (surface); //Destroy the surface pointer, frees up memory and/or lag return 0; //No numbers needed!! }
int main (int argc, char *argv[]) { cairo_surface_t *surface = //Sets the Cairo surface context cairo_image_surface_create (CAIRO_FORMAT_ARGB32, 421, 410); //Creates Cairo image surface, sets image resolution. cairo_t *cr = //Declare *cr as a Cairo context. cairo_create (surface); //Sets the Cairo context as a pointer, *cr. /* Sixth triangle */ cairo_scale (cr, 10, 10); //This is for the outlines only; scaling will mess up already-generated PNGs cairo_move_to (cr, 12.8, 33.0); //This will be removed (probably) in the next revision. cairo_line_to (cr, 19.5, 26.0); //Draws a line from Point A to Point B. cairo_move_to (cr, 19.5, 26.0); //This will be removed (probably) in the next revision. cairo_line_to (cr, 33.3, 35.6); //Draws a line from Point B to Point C. cairo_move_to (cr, 33.3, 35.6); //This will be removed (probably) in the next revision. cairo_line_to (cr, 12.8, 33.0); //Draws a line from Point C back to Point A. cairo_set_line_width (cr, 0.1); //This is an outline, so the width of the line that makes the shape up here is 0.1px thick. cairo_stroke (cr); //Draw the final shape /* Write output and clean up */ cairo_surface_write_to_png (surface, "../images/triangle6-outline.png"); //Name the resulting image as triangle6-outline.png cairo_destroy (cr); //Destroy the context pointer, frees up memory and/or lag cairo_surface_destroy (surface); //Destroy the surface pointer, frees up memory and/or lag return 0; //No numbers needed!! }
int main(void) { int i; int width, height; width = 600; height = 100; cairo_surface_t *surface; cairo_t *cr; surface = cairo_image_surface_create(CAIRO_FORMAT_ARGB32, width, height); cr = cairo_create(surface); for ( i = 1; i <= 10; i++) { cairo_set_source_rgba(cr, 0, 0, 1, i*0.1); cairo_rectangle(cr, 50*i, 40, 40, 40); cairo_fill(cr); } cairo_surface_write_to_png(surface, "transparancy.png"); cairo_destroy(cr); cairo_surface_destroy(surface); return 0; }
/** * gdk_texture_save_to_png: * @texture: a #GdkTexture * @filename: the filename to store to * * Store the given @texture to the @filename as a PNG file. * * This is a utility function intended for debugging and testing. * If you want more control over formats, proper error handling or * want to store to a #GFile or other location, you might want to * look into using the gdk-pixbuf library. * * Returns: %TRUE if saving succeeded, %FALSE on failure. **/ gboolean gdk_texture_save_to_png (GdkTexture *texture, const char *filename) { cairo_surface_t *surface; cairo_status_t status; gboolean result; g_return_val_if_fail (GDK_IS_TEXTURE (texture), FALSE); g_return_val_if_fail (filename != NULL, FALSE); surface = cairo_image_surface_create (CAIRO_FORMAT_ARGB32, gdk_texture_get_width (texture), gdk_texture_get_height (texture)); gdk_texture_download (texture, cairo_image_surface_get_data (surface), cairo_image_surface_get_stride (surface)); cairo_surface_mark_dirty (surface); status = cairo_surface_write_to_png (surface, filename); if (status != CAIRO_STATUS_SUCCESS || cairo_surface_status (surface) != CAIRO_STATUS_SUCCESS) result = FALSE; else result = TRUE; cairo_surface_destroy (surface); return result; }
void renderLabels(const char* path) { BOOST_TEST_MESSAGE("Render: " << path); cairo_surface_t* surface = cairo_image_surface_create(CAIRO_FORMAT_ARGB32, META_TILE_SIZE * TILE_SIZE, META_TILE_SIZE * TILE_SIZE); cairo_t* cr = cairo_create(surface); cairo_set_source_rgba(cr, 0.0, 0.0, 0.0, 1.0); cairo_save(cr); cairo_set_source_rgba(cr, 1.0, 1.0, 1.0, 1.0); cairo_paint(cr); cairo_restore(cr); std::vector<std::pair<string, FloatPoint>> toPlace; toPlace.push_back(std::pair<string, FloatPoint>("Karlsruhe", FloatPoint(40, 200))); toPlace.push_back(std::pair<string, FloatPoint>("Mannheim", FloatPoint(400, 200))); toPlace.push_back(std::pair<string, FloatPoint>("Stuttgard", FloatPoint(200, 260))); toPlace.push_back(std::pair<string, FloatPoint>("München", FloatPoint(380, 660))); toPlace.push_back(std::pair<string, FloatPoint>("Pforzheim", FloatPoint(200, 600))); toPlace.push_back(std::pair<string, FloatPoint>("Wien", FloatPoint(240, 680))); toPlace.push_back(std::pair<string, FloatPoint>("Paris", FloatPoint(40, 880))); toPlace.push_back(std::pair<string, FloatPoint>("Rom", FloatPoint(-40, 880))); toPlace.push_back(std::pair<string, FloatPoint>("Nothing", FloatPoint(400, 760))); toPlace.push_back(std::pair<string, FloatPoint>("To See", FloatPoint(720, 880))); toPlace.push_back(std::pair<string, FloatPoint>("Here", FloatPoint(720, 560))); toPlace.push_back(std::pair<string, FloatPoint>("Bielefeld", FloatPoint(420, 840))); renderer->renderLabels(cr, toPlace); BOOST_TEST_MESSAGE("Writing."); cairo_surface_flush(surface); cairo_surface_write_to_png(surface, path); }
int main (int argc, char **argv) { GList *toplevels; GList *node; /* If there's no DISPLAY, we silently error out. We don't want to break * headless builds. */ if (! gtk_init_check (&argc, &argv)) return 0; toplevels = get_all_widgets (); for (node = toplevels; node; node = g_list_next (node)) { WidgetInfo *info; char *filename; cairo_surface_t *surface; info = node->data; gtk_widget_show (info->window); surface = snapshot_widget (info->window, info->include_decorations ? SNAPSHOT_WINDOW : SNAPSHOT_DRAW); filename = g_strdup_printf ("./%s.png", info->name); g_assert (cairo_surface_write_to_png (surface, filename) == CAIRO_STATUS_SUCCESS); g_free (filename); cairo_surface_destroy (surface); } return 0; }
void ng_view_export_to_file(NgView *view, const gchar *filename) { g_return_if_fail(view != NULL); g_return_if_fail(view->ng != NULL); g_return_if_fail(filename != NULL); NgView *offscreen = ng_view_new(view->ng); guint width = 0, height = 0; ng_view_get_required_size(offscreen, &width, &height); if (width == 0 || height == 0) goto done; ng_view_set_size(offscreen, width, height); cairo_surface_t *surf = cairo_image_surface_create(CAIRO_FORMAT_ARGB32, width, height); cairo_t *cr = cairo_create(surf); ng_view_render(offscreen, cr, FALSE); cairo_destroy(cr); cairo_status_t status = cairo_surface_write_to_png(surf, filename); cairo_surface_destroy(surf); if (status != CAIRO_STATUS_SUCCESS) printf("Error exporting to file `%s'\n", filename); done: ng_view_unref(offscreen); }
/* Methods */ static JSBool writeToPNG_func(JSContext *context, uintN argc, jsval *vp) { jsval *argv = JS_ARGV(context, vp); JSObject *obj = JS_THIS_OBJECT(context, vp); char *filename; cairo_surface_t *surface; if (!gjs_parse_args(context, "writeToPNG", "s", argc, argv, "filename", &filename)) return JS_FALSE; surface = gjs_cairo_surface_get_surface(context, obj); if (!surface) { g_free(filename); return JS_FALSE; } cairo_surface_write_to_png(surface, filename); g_free(filename); if (!gjs_cairo_check_status(context, cairo_surface_status(surface), "surface")) return JS_FALSE; JS_SET_RVAL(context, vp, JSVAL_VOID); return JS_TRUE; }
void CairoPainter::WriteImage(const std::string &filename) { if (!m_cairo || !m_surface) return; cairo_surface_write_to_png(m_surface, filename.c_str()); }
int main() { // Auflösung in Pixeln const double res = 1000; const double xsize = res; const double ysize = sin(M_PI / 3) * res; // Breite einer Linie in Pixeln const double line_width = 3; // maximale Anzahl Iterationen const unsigned int iterations = 7; cairo_surface_t *surface = cairo_image_surface_create ( CAIRO_FORMAT_ARGB32, xsize, ysize); cairo_t *cr = cairo_create (surface); cairo_scale(cr, res, res); cairo_set_line_width (cr, line_width / res); cairo_set_source_rgb (cr, 0, 0, 0); const double space = 0.05; zeichne(cr, space, sin(M_PI / 3) - space, 1 - space, sin(M_PI / 3) - space, 0.5, space, iterations); cairo_destroy (cr); cairo_surface_write_to_png (surface, "sierpinski.png"); cairo_surface_destroy (surface); return 0; }
void finish(void) { if(!surface || !cr) return; cairo_surface_write_to_png(surface, __FILE__ ".png"); cairo_destroy(cr); cairo_surface_destroy(surface); }
void PlatformBinding::TakeScreenshotImpl(const std::string& targetFile) { // Ensure filename ends in .bmp. // TODO: This seems broken. std::string screenshotFile = targetFile; if (screenshotFile.rfind(".") == std::string::npos) screenshotFile.append(".png"); HWND desktop = GetDesktopWindow(); RECT desktopRect; GetWindowRect(desktop, &desktopRect); int width = desktopRect.right; int height = desktopRect.bottom; cairo_surface_t* surface = cairo_win32_surface_create_with_dib(CAIRO_FORMAT_RGB24, width, height); cairo_surface_flush(surface); HDC hdc = cairo_win32_surface_get_dc(surface); BitBlt(hdc, 0, 0, width, height, GetDC(0), 0, 0, SRCCOPY); std::string filename(::UTF8ToSystem(screenshotFile)); cairo_status_t result = cairo_surface_write_to_png(surface, filename.c_str()); cairo_surface_destroy(surface); if (result != CAIRO_STATUS_SUCCESS) throw ValueException::FromString("Could not save screenshot."); }
void n_harm_osz_print_cairo(r_type r, int t) { int i; cairo_surface_t *surface; cairo_t *cr; char filename[40]; sprintf(filename, "n_harm_osz/n_harm_osz_%04d.png", t); surface = cairo_image_surface_create (CAIRO_FORMAT_ARGB32, CAIRO_XSCALE*CAIRO_SCALE, CAIRO_YSCALE*CAIRO_SCALE); cr = cairo_create (surface); /* weißer Hintergrund */ cairo_set_source_rgb (cr, 1, 1, 1); cairo_paint (cr); /* Drawing code goes here */ for(i=0; i < r.N ; i++) { cairo_set_source_rgb (cr, VMIN(fabs(r.vx[i]/VMAX)), VMIN(fabs(r.vy[i]/VMAX)), VMIN(fabs(r.vz[i]/VMAX))); cairo_rectangle (cr, (int) (r.x[i]*CAIRO_SCALE*0.8+0.1*CAIRO_XSCALE*CAIRO_SCALE), (int) (r.y[i]*CAIRO_SCALE*0.8+0.1*CAIRO_YSCALE*CAIRO_SCALE), 1*SCALE, 1*SCALE); cairo_fill (cr); } /* Write output and clean up */ cairo_surface_write_to_png (surface, filename); cairo_destroy (cr); cairo_surface_destroy (surface); }
int main(int argc, char** argv) { cairo_surface_t *surface; cairo_t *cr; surface = cairo_image_surface_create (CAIRO_FORMAT_ARGB32, 1300, 760); cr = cairo_create (surface); int w, h; cairo_surface_t *image; cairo_arc (cr, 128.0, 128.0, 76.8, 0, 2*M_PI); cairo_clip (cr); cairo_new_path (cr); /* path not consumed by clip()*/ image = cairo_image_surface_create_from_png ("new.png"); w = cairo_image_surface_get_width (image); h = cairo_image_surface_get_height (image); cairo_scale (cr, 256.0/w, 256.0/h); cairo_set_source_surface (cr, image, 0, 0); cairo_paint (cr); cairo_surface_destroy (image); cairo_destroy (cr); cairo_surface_write_to_png (surface, "hello.png"); cairo_surface_destroy (surface); return 0; }
int main (int argc, char **argv) { cairo_t *cr; char *filename; cairo_status_t status; cairo_surface_t *surface; if (argc != 2) { g_printerr ("Usage: cairosimple OUTPUT_FILENAME\n"); return 1; } filename = argv[1]; surface = cairo_image_surface_create (CAIRO_FORMAT_ARGB32, 2 * RADIUS, 2 * RADIUS); cr = cairo_create (surface); cairo_set_source_rgb (cr, 1.0, 1.0, 1.0); cairo_paint (cr); draw_text (cr); cairo_destroy (cr); status = cairo_surface_write_to_png (surface, filename); cairo_surface_destroy (surface); if (status != CAIRO_STATUS_SUCCESS) { g_printerr ("Could not save png to '%s'\n", filename); return 1; } return 0; }
void draw_map(char *filename) { cairo_surface_t *surface; cairo_t *cr; int width; int height; int rec_x; int rec_y; int rec_width; int rec_height; width = 1280; height = 720; rec_x = 320; rec_y = 240; rec_width = 30; rec_height = 300; surface = cairo_image_surface_create(CAIRO_FORMAT_ARGB32, width, height); cr = cairo_create(surface); cairo_set_source_rgb(cr, 0, 0, 0); cairo_paint(cr); render_map(cr); cairo_surface_write_to_png(surface, filename); cairo_destroy(cr); cairo_surface_destroy(surface); }
static void render_cairo_surface (const RENDER * render, SNDFILE *infile, int samplerate, sf_count_t filelen) { cairo_surface_t * surface = NULL ; cairo_status_t status ; /* ** CAIRO_FORMAT_RGB24 each pixel is a 32-bit quantity, with the upper 8 bits ** unused. Red, Green, and Blue are stored in the remaining 24 bits in that order. */ surface = cairo_image_surface_create (CAIRO_FORMAT_RGB24, render->width, render->height) ; if (surface == NULL || cairo_surface_status (surface) != CAIRO_STATUS_SUCCESS) { status = cairo_surface_status (surface) ; printf ("Error while creating surface : %s\n", cairo_status_to_string (status)) ; exit (1) ; } ; cairo_surface_flush (surface) ; render_to_surface (render, infile, samplerate, filelen, surface) ; status = cairo_surface_write_to_png (surface, render->pngfilepath) ; if (status != CAIRO_STATUS_SUCCESS) { printf ("Error while creating PNG file : %s\n", cairo_status_to_string (status)) ; exit (1) ; } ; cairo_surface_destroy (surface) ; return ; } /* render_cairo_surface */
/* METH_O */ static PyObject * surface_write_to_png (PycairoSurface *o, PyObject *file) { cairo_status_t status; if (PyObject_TypeCheck (file, &PyBaseString_Type)) { /* string (filename) argument */ status = cairo_surface_write_to_png (o->surface, PyString_AsString(file)); } else { /* file or file-like object argument */ PyObject* writer = PyObject_GetAttrString (file, "write"); if (writer == NULL || !PyCallable_Check (writer)) { Py_XDECREF(writer); PyErr_SetString(PyExc_TypeError, "Surface.write_to_png takes one argument which must be a filename (str), file " "object, or a file-like object which has a \"write\" method (like StringIO)"); return NULL; } Py_DECREF(writer); status = cairo_surface_write_to_png_stream (o->surface, _write_func, file); } RETURN_NULL_IF_CAIRO_ERROR(status); Py_RETURN_NONE; }
void CairoRenderer::RenderPage(const Dictionary *pPage, double dWidth, double dHeight) { cairo_surface_t *pSurface; char str[32]; pSurface = cairo_image_surface_create(CAIRO_FORMAT_ARGB32, dWidth, dHeight); m_pCairo = cairo_create(pSurface); cairo_set_source_rgba(m_pCairo, 1.0, 1.0, 1.0, 1.0); cairo_paint(m_pCairo); m_pStrokeColor[0] = 0.0; m_pStrokeColor[1] = 0.0; m_pStrokeColor[2] = 0.0; cairo_set_source_rgba(m_pCairo, 0.0, 0.0, 0.0, 1.0); cairo_set_line_width(m_pCairo, 0.5); cairo_set_miter_limit(m_pCairo, 10.0); m_nTextMode = 0; m_dTextLead = 0.0; m_pFontMatrix = new cairo_matrix_t; cairo_translate(m_pCairo, 0, dHeight); cairo_scale(m_pCairo, 1.0, -1.0); Renderer::RenderPage(pPage, dWidth, dHeight); sprintf(str, "%d.png", m_nPage); cairo_surface_write_to_png(pSurface, str); delete m_pFontMatrix; cairo_destroy(m_pCairo); cairo_surface_destroy(pSurface); }
static SeedValue seed_cairo_surface_write_to_png (SeedContext ctx, SeedObject function, SeedObject this_object, gsize argument_count, const SeedValue arguments[], SeedException *exception) { cairo_status_t ret; cairo_surface_t *surf; gchar *filename; CHECK_THIS(); if (argument_count != 1) { EXPECTED_EXCEPTION("write_to_png", "1 argument"); } surf = seed_object_get_private (this_object); filename = seed_value_to_string (ctx, arguments[0], exception); ret = cairo_surface_write_to_png (surf, filename); g_free (filename); return seed_value_from_long (ctx, ret, exception); }
bool AP_UnixApp::makePngPreview(const char * pszInFile, const char * pszPNGFile, UT_sint32 iWidth, UT_sint32 iHeight) { cairo_surface_t *surface = cairo_image_surface_create (CAIRO_FORMAT_RGB24, iWidth, iHeight); cairo_t *cr = cairo_create (surface); GR_UnixCairoAllocInfo ai(NULL, false); GR_CairoGraphics * pG = static_cast<GR_CairoGraphics*>(GR_UnixCairoGraphics::graphicsAllocator(ai)); pG->setCairo(cr); pG->beginPaint(); // needed to avoid cairo reference loss UT_Error error = UT_OK; PD_Document * pNewDoc = new PD_Document(); error = pNewDoc->readFromFile(pszInFile,IEFT_Unknown, NULL); if (error != UT_OK) { return false; } AP_Preview_Abi * pPrevAbi = new AP_Preview_Abi(pG,iWidth,iHeight,NULL, PREVIEW_ZOOMED,pNewDoc); dg_DrawArgs da; memset(&da, 0, sizeof(da)); da.pG = pG; GR_Painter * pPaint = new GR_Painter(pG); pPaint->clearArea(0,0,pG->tlu(iWidth),pG->tlu(iHeight)); pPrevAbi->getView()->draw(0, &da); pG->endPaint(); cairo_destroy(cr); DELETEP(pPaint); cairo_surface_write_to_png(surface, pszPNGFile); cairo_surface_destroy(surface); DELETEP(pG); DELETEP(pPrevAbi); // This deletes pNewDoc return true; }
static void BM_Close_bitmap(pX11Desc xd) { if (xd->type == PNGdirect) { char buf[PATH_MAX]; snprintf(buf, PATH_MAX, xd->filename, xd->npages); cairo_surface_write_to_png(xd->cs, buf); return; } void *xi = cairo_image_surface_get_data(xd->cs); if (!xi) { warning("BM_Close_bitmap called on non-surface"); return; } stride = cairo_image_surface_get_stride(xd->cs)/4; if (xd->type == PNG) R_SaveAsPng(xi, xd->windowWidth, xd->windowHeight, Cbitgp, 0, xd->fp, 0, xd->res_dpi); else if(xd->type == JPEG) R_SaveAsJpeg(xi, xd->windowWidth, xd->windowHeight, Cbitgp, 0, xd->quality, xd->fp, xd->res_dpi); else if(xd->type == BMP) R_SaveAsBmp(xi, xd->windowWidth, xd->windowHeight, Cbitgp, 0, xd->fp, xd->res_dpi); else { char buf[PATH_MAX]; snprintf(buf, PATH_MAX, xd->filename, xd->npages); R_SaveAsTIFF(xi, xd->windowWidth, xd->windowHeight, Cbitgp, 0, R_ExpandFileName(buf), xd->res_dpi, xd->quality); } }
int plot_time_series_paint_frame(double * x, double * y, double t, int n, int x_max, int y_max) { int i; cairo_surface_t *surface; cairo_t *cr; char filename[40]; sprintf(filename, "rk4/rk4_%05.0f.png", t*100); surface = cairo_image_surface_create (CAIRO_FORMAT_ARGB32, CAIRO_SCALE*x_max, CAIRO_SCALE*y_max); cr = cairo_create (surface); cairo_scale (cr, CAIRO_SCALE, CAIRO_SCALE); /* weißer Hintergrund */ cairo_set_source_rgb (cr, 1, 1, 1); cairo_paint (cr); /* Drawing code goes here */ cairo_set_source_rgb (cr, 0, 0, 0); for(i=0;i<n;i++) { cairo_rectangle (cr, x[i]+x_max/2, y[i]+y_max/2, 1, 1); //~ cairo_rectangle (cr, x[i]+x_max/2, y[i], 1, 1); } cairo_fill (cr); /* Write output and clean up */ cairo_surface_write_to_png (surface, filename); cairo_destroy (cr); cairo_surface_destroy (surface); return 0; }
void DrawerSave(Drawer * self, char fileTypePDF, const char * filePath) { if(fileTypePDF) { cairo_show_page(self->context); } else { cairo_surface_write_to_png(self->surface, filePath); } }
void TreeNode::draw() const { std::ofstream ofs(NODE_FILENAME); cairo_t *cr; cairo_surface_t *surface; CGAL::Bbox_2 bbox = region.bbox(); assert(bbox.xmin() >= 0.0); assert(bbox.ymin() >= 0.0); #ifdef PDF_OUTPUT surface = cairo_pdf_surface_create(IMG_FILENAME, bbox.xmax(), bbox.ymax()); #endif #ifdef PNG_OUTPUT surface = cairo_image_surface_create(CAIRO_FORMAT_ARGB32, bbox.xmax(), bbox.ymax()); #endif cr = cairo_create(surface); cairo_select_font_face(cr, "serif", CAIRO_FONT_SLANT_NORMAL, CAIRO_FONT_WEIGHT_BOLD); cairo_set_font_size(cr, 10.0); draw_region(cr); draw_text(cr); write_centroid(ofs); cairo_show_page(cr); cairo_destroy(cr); #ifdef PNG_OUTPUT cairo_surface_write_to_png(surface, IMG_FILENAME); #endif cairo_surface_destroy(surface); }
void render_rectangle(char *filename) { cairo_surface_t *surface; cairo_t *cr; int width; int height; int rec_x; int rec_y; int rec_width; int rec_height; width = 1280; height = 720; rec_x = 320; rec_y = 240; rec_width = 30; rec_height = 300; surface = cairo_image_surface_create(CAIRO_FORMAT_ARGB32, width, height); cr = cairo_create(surface); // Fill with white (default is transparent) cairo_set_source_rgb(cr, 1.0, 1.0, 1.0); cairo_paint(cr); krad_vector_render_rrect(cr, rec_x, rec_y, rec_width, rec_height, 0.8, 0.2, 0.2, 0.5); cairo_surface_write_to_png(surface, filename); cairo_destroy(cr); cairo_surface_destroy(surface); }
static gboolean expose_event (GtkWidget *w, GdkEventExpose *ev, struct options *options) { cairo_t *cr; cr = gdk_cairo_create (w->window); cairo_set_source_rgb (cr, 1, 1, 1); cairo_paint (cr); draw (cr, options); cairo_destroy (cr); if (options->png) { cairo_surface_t *image; image = cairo_image_surface_create (CAIRO_FORMAT_RGB24, w->allocation.width, w->allocation.height); cr = cairo_create (image); cairo_set_source_rgb (cr, 1, 1, 1); cairo_paint (cr); draw (cr, options); cairo_destroy (cr); cairo_surface_write_to_png (image, options->png); cairo_surface_destroy (image); } return TRUE; }
G_MODULE_EXPORT void btn_save_cb(GtkButton *btn, gpointer data) { cairo_t *cr; cairo_surface_t *surface; int i; double y; surface = cairo_image_surface_create(CAIRO_FORMAT_ARGB32, 512, 500); cr = cairo_create (surface); paint_bg(cr); paint_marker(cr); //画图(蓝色) cairo_set_line_width(cr, 1); cairo_set_source_rgb(cr, 0, 0, 1); y = TOY(buffer[0])>500 ? 500 : TOY(buffer[0]); cairo_move_to(cr, 0, TOY(buffer[0])); for (i=1; i<512; i++) { y = cfg.yref + yscale*TOY(buffer[i-1]); //cairo_line_to(cr, i-1, cfg.yref+yscale*TOY(buffer[i-1])); cairo_line_to(cr, i-1, y>500?500:y); } cairo_stroke(cr); cairo_surface_write_to_png(surface, "save.png"); cairo_destroy(cr); cairo_surface_destroy(surface); }