网页资讯视频图片知道文库贴吧地图采购
进入贴吧全吧搜索

 
 
 
日一二三四五六
       
       
       
       
       
       

签到排名:今日本吧第个签到,

本吧因你更精彩,明天继续来努力!

本吧签到人数:0

一键签到
成为超级会员,使用一键签到
一键签到
本月漏签0次!
0
成为超级会员,赠送8张补签卡
如何使用?
点击日历上漏签日期,即可进行补签。
连续签到:天  累计签到:天
0
超级会员单次开通12个月以上,赠送连续签到卡3张
使用连续签到卡
02月03日漏签0天
c语言吧 关注:801,842贴子:4,375,749
  • 看贴

  • 图片

  • 吧主推荐

  • 视频

  • 游戏

  • 首页 上一页 1 2 3
  • 52回复贴,共3页
  • ,跳到 页  
<<返回c语言吧
>0< 加载中...

回复:Cairo & C语言 & GTK+3.0 & Linux

  • 只看楼主
  • 收藏

  • 回复
  • AutoRunAs
  • 麻婆豆腐
    11
该楼层疑似违规已被系统折叠 隐藏此楼查看此楼

/* cairo027.c 模式 cairo_mesh_pattern_curve_to */
#include <cairo.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
static cairo_surface_t *surface = NULL;
struct df_canvas
{
char filename[28];
int type;
double width;
double height;
};
void df_draw_brush (struct df_canvas const *pcanvas)
{
cairo_t *cr;
cairo_pattern_t *pat;
cr = cairo_create (surface);
pat = cairo_pattern_create_mesh();
cairo_set_source_rgba (cr, 0.1, 0.1, 0.1, 0.9);
/* 第一张图 */
cairo_mesh_pattern_begin_patch (pat);
cairo_mesh_pattern_move_to (pat, 120, 100);
cairo_mesh_pattern_curve_to (pat, 120, 300, 450, 300, 450, 100);
cairo_mesh_pattern_set_corner_color_rgba (pat, 0, 1, 0, 0, 0.9); /* 红 */
cairo_mesh_pattern_set_corner_color_rgba (pat, 1, 0, 1, 0, 0.9); /* 绿 */
cairo_mesh_pattern_set_corner_color_rgba (pat, 2, 0, 0, 1, 0.9); /* 蓝 */
cairo_mesh_pattern_end_patch (pat);
cairo_rectangle (cr, 50, 50, 500, 220);
cairo_fill_preserve (cr);
/* 第二张图 */
cairo_mesh_pattern_begin_patch (pat);
cairo_mesh_pattern_move_to (pat, 120, 370);
cairo_mesh_pattern_curve_to (pat, 120, 570, 450, 570, 450, 370);
cairo_mesh_pattern_curve_to (pat, 240, 570, 240, 670, 120, 770);
cairo_mesh_pattern_set_corner_color_rgba (pat, 0, 1, 0, 0, 0.9); /* 红 */
cairo_mesh_pattern_set_corner_color_rgba (pat, 1, 0, 1, 0, 0.9); /* 绿 */
cairo_mesh_pattern_set_corner_color_rgba (pat, 2, 0, 0, 1, 0.9); /* 蓝 */
cairo_mesh_pattern_end_patch (pat);
cairo_rectangle (cr, 50, 290, 500, 570);
cairo_fill_preserve (cr);
/* */
cairo_set_source (cr, pat);
cairo_fill (cr);
cairo_stroke (cr);
cairo_surface_write_to_png (surface, pcanvas -> filename);
cairo_pattern_destroy (pat);
cairo_destroy (cr);
}
void df_init_canvas (struct df_canvas const *pcanvas)
{
surface = cairo_image_surface_create (CAIRO_FORMAT_ARGB32, (int) pcanvas -> width, (int) pcanvas -> height);
}
int main (int argc, char *argv[])
{
struct df_canvas *canvas;
canvas = (struct df_canvas*) malloc (sizeof (struct df_canvas));
strncpy(canvas -> filename, "hello.png",28);
canvas -> type = CAIRO_SURFACE_TYPE_IMAGE;
canvas -> width = 600.0;
canvas -> height = 900.0;
df_init_canvas (canvas);
df_draw_brush (canvas);
free (canvas);
if (surface != NULL) cairo_surface_destroy (surface);
return 0;
}


  • AutoRunAs
  • 麻婆豆腐
    11
该楼层疑似违规已被系统折叠 隐藏此楼查看此楼

/* cairo028.c 模式 cairo_mesh_pattern_curve_to */
#include <cairo.h>
#include <stdlib.h>
#include <string.h>
static cairo_surface_t *surface = NULL;
struct df_canvas
{
char filename[28];
int type;
double width;
double height;
};
void df_draw_brush (struct df_canvas const *pcanvas)
{
cairo_t *cr;
cairo_pattern_t *pat;
cr = cairo_create (surface);
pat = cairo_pattern_create_mesh();
cairo_set_source_rgba (cr, 0.1, 0.1, 0.1, 0.9);
cairo_translate (cr, 300, 180); /* 设置世界坐标 */
cairo_mesh_pattern_begin_patch (pat);
cairo_mesh_pattern_move_to (pat, 0, 0);
cairo_mesh_pattern_curve_to (pat, 30, -30, 60, 30, 100, 0); /* 上 */
cairo_mesh_pattern_curve_to (pat, 60, 30, 130, 60, 100, 100); /* 右 */
cairo_mesh_pattern_curve_to (pat, 60, 70, 30, 130, 0, 100); /* 下 */
cairo_mesh_pattern_curve_to (pat, 30, 70, -30, 30, 0, 0); /* 左 */
cairo_mesh_pattern_set_corner_color_rgb (pat, 0, 1, 0, 0); /* 红 */
cairo_mesh_pattern_set_corner_color_rgb (pat, 1, 0, 1, 0); /* 绿 */
cairo_mesh_pattern_set_corner_color_rgb (pat, 2, 0, 0, 1); /* 蓝 */
cairo_mesh_pattern_set_corner_color_rgb (pat, 3, 1, 1, 0); /* 黄 */
cairo_mesh_pattern_end_patch (pat);
cairo_rectangle (cr, -250, -150, 500, 320);
cairo_fill_preserve (cr);
cairo_set_source (cr, pat);
cairo_fill (cr);
cairo_stroke (cr);
cairo_surface_write_to_png (surface, pcanvas -> filename);
cairo_pattern_destroy (pat);
cairo_destroy (cr);
}
void df_init_canvas (struct df_canvas const *pcanvas)
{
surface = cairo_image_surface_create (CAIRO_FORMAT_ARGB32, (int) pcanvas -> width, (int) pcanvas -> height);
}
int main (int argc, char *argv[])
{
struct df_canvas *canvas;
canvas = (struct df_canvas*) malloc (sizeof (struct df_canvas));
strncpy(canvas -> filename, "hello.png",28);
canvas -> type = CAIRO_SURFACE_TYPE_IMAGE;
canvas -> width = 600.0;
canvas -> height = 370.0;
df_init_canvas (canvas);
df_draw_brush (canvas);
free (canvas);
if (surface != NULL) cairo_surface_destroy (surface);
return 0;
}


2026-02-03 14:35:38
广告
不感兴趣
开通SVIP免广告
  • AutoRunAs
  • 麻婆豆腐
    11
该楼层疑似违规已被系统折叠 隐藏此楼查看此楼

/* cairo029.c cairo_pattern_create_linear */
#include <cairo.h>
#include <stdlib.h>
#include <string.h>
static cairo_surface_t *surface = NULL;
struct df_canvas
{
char filename[28];
int type;
double width;
double height;
};
void df_draw_brush (struct df_canvas const *pcanvas)
{
cairo_t *cr;
cairo_pattern_t *pat;
double i, k;
int count;
cr = cairo_create (surface);
/* 红黑 */
pat = cairo_pattern_create_linear (80.0, 80.0, 550.0, 350.0); /* 左上至右下 */
count = 1;
for (i = 0.1; i < 1; i += 0.1)
{
k = (count % 2 == 0) ? 0.0 : 1.0;
cairo_pattern_add_color_stop_rgba (pat, i, k, 0.0, 0.0, 0.7);
count++;
}
cairo_rectangle (cr, 80, 50, 450, 153);
cairo_set_source (cr, pat);
cairo_fill (cr);
/* 绿黑 */
pat = cairo_pattern_create_linear (50.0, 250.0, 580.0, 250.0); /* 从左到右 (Y不变)*/
count = 1;
for (i = 0.05; i < 0.95; i += 0.025)
{
k = (count % 2 == 0) ? 0.0 : 1.0;
cairo_pattern_add_color_stop_rgba (pat, i, 0, k, 0.0, 0.7);
count++;
}
cairo_rectangle (cr, 80, 250, 450, 153);
cairo_set_source (cr, pat);
cairo_fill (cr);
/* 黄黑 */
pat = cairo_pattern_create_linear (80.0, 450.0, 80.0, 600.0); /* 从上到下 (X不变) */
cairo_pattern_add_color_stop_rgba (pat, 0.1, 0.0, 0.0, 0.0, 0.7);
cairo_pattern_add_color_stop_rgba (pat, 0.5, 1.0, 1.0, 0.0, 0.7);
cairo_pattern_add_color_stop_rgba (pat, 0.9, 0.0, 0.0, 0.0, 0.7);
cairo_rectangle (cr, 80, 450, 450, 153);
cairo_set_source (cr, pat);
cairo_fill (cr);
cairo_surface_write_to_png (surface, pcanvas -> filename);
cairo_destroy (cr);
}
void df_init_canvas (struct df_canvas const *pcanvas)
{
surface = cairo_image_surface_create (CAIRO_FORMAT_ARGB32, (int) pcanvas -> width, (int) pcanvas -> height);
}
int main (int argc, char *argv[])
{
struct df_canvas *canvas;
canvas = (struct df_canvas*) malloc (sizeof (struct df_canvas));
strncpy(canvas -> filename, "hello.png", 28);
canvas -> type = CAIRO_SURFACE_TYPE_IMAGE;
canvas -> width = 600.0;
canvas -> height = 660.0;
df_init_canvas (canvas);
df_draw_brush (canvas);
free (canvas);
if (surface != NULL) cairo_surface_destroy (surface);
return 0;
}


  • AutoRunAs
  • 麻婆豆腐
    11
该楼层疑似违规已被系统折叠 隐藏此楼查看此楼

/* cairo030.c 混合操作 cairo_set_operator */
#include <cairo.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
static cairo_surface_t *surface = NULL;
struct df_canvas
{
char filename[28];
int type;
double width;
double height;
};
static void df_draw_brush (struct df_canvas const *pcanvas, cairo_operator_t op, double height)
{
cairo_t *cr;
cr = cairo_create (surface);
cairo_t *arc_cr, *rect_cr;
cairo_surface_t *arc_surface, *rect_surface;
/* 圆弧-红边黄色填充 */
arc_surface = cairo_surface_create_similar (cairo_get_target (cr), CAIRO_CONTENT_COLOR_ALPHA, 600, 370);
arc_cr = cairo_create (arc_surface);
cairo_arc (arc_cr, 300, 170, 100, 0, 2 * M_PI);
cairo_set_line_width (arc_cr, 20);
cairo_set_source_rgb (arc_cr, 0.9, 0.0, 0.0);
cairo_stroke_preserve (arc_cr);
cairo_set_source_rgb (arc_cr, 0.9, 0.9, 0.0);
cairo_fill (arc_cr);
/* 四边形 - 黑边蓝色填充 */
rect_surface = cairo_surface_create_similar (cairo_get_target (cr), CAIRO_CONTENT_COLOR_ALPHA, 600, 370);
rect_cr = cairo_create (rect_surface);
cairo_rectangle (rect_cr, 50, 50, 250, 250);
cairo_set_line_width (rect_cr, 20);
cairo_set_source_rgb (rect_cr, 0.0, 0.0, 0.0);
cairo_stroke_preserve (rect_cr);
cairo_set_source_rgb (rect_cr, 0.0, 0.0, 0.9);
cairo_fill (rect_cr);
/* 混合两个画布内容 */
cairo_set_operator (arc_cr, op); /* 设置混合操作 */
cairo_set_source_surface (arc_cr, rect_surface, 0, 0);
cairo_paint (arc_cr);
cairo_set_source_surface (cr, arc_surface, 0, height);
cairo_paint (cr);
cairo_stroke (cr);
cairo_surface_write_to_png (surface, pcanvas -> filename);
cairo_surface_destroy (arc_surface);
cairo_surface_destroy (rect_surface);
cairo_destroy (arc_cr);
cairo_destroy (rect_cr);
cairo_destroy (cr);
}
void df_init_canvas (struct df_canvas const *pcanvas)
{
surface = cairo_image_surface_create (CAIRO_FORMAT_ARGB32, (int) pcanvas -> width, (int) pcanvas -> height);
}
int main (int argc, char *argv[])
{
struct df_canvas *canvas;
canvas = (struct df_canvas*) malloc (sizeof (struct df_canvas));
strncpy(canvas -> filename, "hello.png", 28);
canvas -> type = CAIRO_SURFACE_TYPE_IMAGE;
canvas -> width = 600.0;
canvas -> height = 1600.0;
df_init_canvas (canvas);
int i;
cairo_operator_t op[] = {
CAIRO_OPERATOR_SOURCE, /* 忽略目标层 */
CAIRO_OPERATOR_OVER, /* 源在目标上层绘制 */
CAIRO_OPERATOR_IN, /* 留下目标包含的内容 */
CAIRO_OPERATOR_OUT, /* 留下目标不包含的内容 */
CAIRO_OPERATOR_ATOP /* 留下目标和目标包含的源内容 */
};
for (i = 0; i < 5; i++)
{
df_draw_brush (canvas, op[i], i * 300.0);
}
free (canvas);
if (surface != NULL) cairo_surface_destroy (surface);
return 0;
}


  • AutoRunAs
  • 麻婆豆腐
    11
该楼层疑似违规已被系统折叠 隐藏此楼查看此楼

/* cairo031.c 混合操作 cairo_set_operator */
#include <cairo.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
static cairo_surface_t *surface = NULL;
struct df_canvas
{
char filename[28];
int type;
double width;
double height;
};
static void df_draw_brush (struct df_canvas const *pcanvas, cairo_operator_t op, double height)
{
cairo_t *cr;
cr = cairo_create (surface);
cairo_t *arc_cr, *rect_cr;
cairo_surface_t *arc_surface, *rect_surface;
/* 圆弧-红边黄色填充 */
arc_surface = cairo_surface_create_similar (cairo_get_target (cr), CAIRO_CONTENT_COLOR_ALPHA, 600, 370);
arc_cr = cairo_create (arc_surface);
cairo_arc (arc_cr, 300, 170, 100, 0, 2 * M_PI);
cairo_set_line_width (arc_cr, 20);
cairo_set_source_rgb (arc_cr, 0.9, 0.0, 0.0);
cairo_stroke_preserve (arc_cr);
cairo_set_source_rgb (arc_cr, 0.9, 0.9, 0.0);
cairo_fill (arc_cr);
/* 四边形 - 黑边蓝色填充 */
rect_surface = cairo_surface_create_similar (cairo_get_target (cr), CAIRO_CONTENT_COLOR_ALPHA, 600, 370);
rect_cr = cairo_create (rect_surface);
cairo_rectangle (rect_cr, 50, 50, 250, 250);
cairo_set_line_width (rect_cr, 20);
cairo_set_source_rgb (rect_cr, 0.0, 0.0, 0.0);
cairo_stroke_preserve (rect_cr);
cairo_set_source_rgb (rect_cr, 0.0, 0.0, 0.9);
cairo_fill (rect_cr);
/* 混合两个画布内容 */
cairo_set_operator (arc_cr, op); /* 设置混合操作 */
cairo_set_source_surface (arc_cr, rect_surface, 0, 0);
cairo_paint (arc_cr);
cairo_set_source_surface (cr, arc_surface, 0, height);
cairo_paint (cr);
cairo_stroke (cr);
cairo_surface_write_to_png (surface, pcanvas -> filename);
cairo_surface_destroy (arc_surface);
cairo_surface_destroy (rect_surface);
cairo_destroy (arc_cr);
cairo_destroy (rect_cr);
cairo_destroy (cr);
}
void df_init_canvas (struct df_canvas const *pcanvas)
{
surface = cairo_image_surface_create (CAIRO_FORMAT_ARGB32, (int) pcanvas -> width, (int) pcanvas -> height);
}
int main (int argc, char *argv[])
{
struct df_canvas *canvas;
canvas = (struct df_canvas*) malloc (sizeof (struct df_canvas));
strncpy(canvas -> filename, "hello.png", 28);
canvas -> type = CAIRO_SURFACE_TYPE_IMAGE;
canvas -> width = 600.0;
canvas -> height = 1600.0;
df_init_canvas (canvas);
int i;
cairo_operator_t op[] = {
CAIRO_OPERATOR_DEST, /* 忽略源 */
CAIRO_OPERATOR_DEST_OVER, /* 在源顶层绘制 */
CAIRO_OPERATOR_DEST_IN, /* 留下源包含的内容 */
CAIRO_OPERATOR_DEST_OUT, /* 留下源不包含的内容 */
CAIRO_OPERATOR_DEST_ATOP /* 留下源和源包含的内容 */
};
for (i = 0; i < 5; i++)
{
df_draw_brush (canvas, op[i], i * 300.0);
}
free (canvas);
if (surface != NULL) cairo_surface_destroy (surface);
return 0;
}


  • AutoRunAs
  • 麻婆豆腐
    11
该楼层疑似违规已被系统折叠 隐藏此楼查看此楼

/* cairo032.c 混合操作 cairo_set_operator */
#include <cairo.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
static cairo_surface_t *surface = NULL;
struct df_canvas
{
char filename[28];
int type;
double width;
double height;
};
static void df_draw_brush (struct df_canvas const *pcanvas, cairo_operator_t op, double height)
{
cairo_t *cr;
cr = cairo_create (surface);
cairo_t *arc_cr, *rect_cr;
cairo_surface_t *arc_surface, *rect_surface;
/* 圆弧-红边黄色填充 */
arc_surface = cairo_surface_create_similar (cairo_get_target (cr), CAIRO_CONTENT_COLOR_ALPHA, 600, 370);
arc_cr = cairo_create (arc_surface);
cairo_arc (arc_cr, 300, 170, 100, 0, 2 * M_PI);
cairo_set_line_width (arc_cr, 20);
cairo_set_source_rgb (arc_cr, 0.9, 0.0, 0.0);
cairo_stroke_preserve (arc_cr);
cairo_set_source_rgb (arc_cr, 0.9, 0.9, 0.0);
cairo_fill (arc_cr);
/* 四边形 - 黑边蓝色填充 */
rect_surface = cairo_surface_create_similar (cairo_get_target (cr), CAIRO_CONTENT_COLOR_ALPHA, 600, 370);
rect_cr = cairo_create (rect_surface);
cairo_rectangle (rect_cr, 50, 50, 250, 250);
cairo_set_line_width (rect_cr, 20);
cairo_set_source_rgb (rect_cr, 0.0, 0.0, 0.0);
cairo_stroke_preserve (rect_cr);
cairo_set_source_rgb (rect_cr, 0.0, 0.0, 0.9);
cairo_fill (rect_cr);
/* 混合两个画布内容 */
cairo_set_operator (arc_cr, op); /* 设置混合操作 */
cairo_set_source_surface (arc_cr, rect_surface, 0, 0);
cairo_paint (arc_cr);
cairo_set_source_surface (cr, arc_surface, 0, height);
cairo_paint (cr);
cairo_stroke (cr);
cairo_surface_write_to_png (surface, pcanvas -> filename);
cairo_surface_destroy (arc_surface);
cairo_surface_destroy (rect_surface);
cairo_destroy (arc_cr);
cairo_destroy (rect_cr);
cairo_destroy (cr);
}
void df_init_canvas (struct df_canvas const *pcanvas)
{
surface = cairo_image_surface_create (CAIRO_FORMAT_ARGB32, (int) pcanvas -> width, (int) pcanvas -> height);
}
int main (int argc, char *argv[])
{
struct df_canvas *canvas;
canvas = (struct df_canvas*) malloc (sizeof (struct df_canvas));
strncpy(canvas -> filename, "hello.png", 28);
canvas -> type = CAIRO_SURFACE_TYPE_IMAGE;
canvas -> width = 600.0;
canvas -> height = 1000.0;
df_init_canvas (canvas);
int i;
cairo_operator_t op[] = {
CAIRO_OPERATOR_XOR,
CAIRO_OPERATOR_ADD,
CAIRO_OPERATOR_SATURATE
};
for (i = 0; i < 3; i++)
{
df_draw_brush (canvas, op[i], i * 300.0);
}
free (canvas);
if (surface != NULL) cairo_surface_destroy (surface);
return 0;
}


  • AutoRunAs
  • 麻婆豆腐
    11
该楼层疑似违规已被系统折叠 隐藏此楼查看此楼

/* cairo033.c 混合操作 cairo_set_operator */
#include <cairo.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
static cairo_surface_t *surface = NULL;
struct df_canvas
{
char filename[28];
int type;
double width;
double height;
};
static void df_draw_brush (struct df_canvas const *pcanvas, cairo_operator_t op, double height)
{
cairo_t *cr;
cr = cairo_create (surface);
cairo_t *arc_cr, *rect_cr;
cairo_surface_t *arc_surface, *rect_surface;
/* 圆弧-红边黄色填充 */
arc_surface = cairo_surface_create_similar (cairo_get_target (cr), CAIRO_CONTENT_COLOR_ALPHA, 600, 370);
arc_cr = cairo_create (arc_surface);
cairo_arc (arc_cr, 300, 170, 100, 0, 2 * M_PI);
cairo_set_line_width (arc_cr, 20);
cairo_set_source_rgb (arc_cr, 0.9, 0.0, 0.0);
cairo_stroke_preserve (arc_cr);
cairo_set_source_rgb (arc_cr, 0.9, 0.9, 0.0);
cairo_fill (arc_cr);
/* 四边形 - 黑边蓝色填充 */
rect_surface = cairo_surface_create_similar (cairo_get_target (cr), CAIRO_CONTENT_COLOR_ALPHA, 600, 370);
rect_cr = cairo_create (rect_surface);
cairo_rectangle (rect_cr, 50, 50, 250, 250);
cairo_set_line_width (rect_cr, 20);
cairo_set_source_rgb (rect_cr, 0.0, 0.0, 0.0);
cairo_stroke_preserve (rect_cr);
cairo_set_source_rgb (rect_cr, 0.0, 0.0, 0.9);
cairo_fill (rect_cr);
/* 混合两个画布内容 */
cairo_set_operator (arc_cr, op); /* 设置混合操作 */
cairo_set_source_surface (arc_cr, rect_surface, 0, 0);
cairo_paint (arc_cr);
cairo_set_source_surface (cr, arc_surface, 0, height);
cairo_paint (cr);
cairo_stroke (cr);
cairo_surface_write_to_png (surface, pcanvas -> filename);
cairo_surface_destroy (arc_surface);
cairo_surface_destroy (rect_surface);
cairo_destroy (arc_cr);
cairo_destroy (rect_cr);
cairo_destroy (cr);
}
void df_init_canvas (struct df_canvas const *pcanvas)
{
surface = cairo_image_surface_create (CAIRO_FORMAT_ARGB32, (int) pcanvas -> width, (int) pcanvas -> height);
}
int main (int argc, char *argv[])
{
struct df_canvas *canvas;
canvas = (struct df_canvas*) malloc (sizeof (struct df_canvas));
strncpy(canvas -> filename, "hello.png", 28);
canvas -> type = CAIRO_SURFACE_TYPE_IMAGE;
canvas -> width = 600.0;
canvas -> height = 1500.0;
df_init_canvas (canvas);
int i;
cairo_operator_t op[] = {
CAIRO_OPERATOR_MULTIPLY,
CAIRO_OPERATOR_SCREEN,
CAIRO_OPERATOR_OVERLAY,
CAIRO_OPERATOR_DARKEN,
CAIRO_OPERATOR_LIGHTEN
};
for (i = 0; i < 5; i++)
{
df_draw_brush (canvas, op[i], i * 300.0);
}
free (canvas);
if (surface != NULL) cairo_surface_destroy (surface);
return 0;
}


  • AutoRunAs
  • 麻婆豆腐
    11
该楼层疑似违规已被系统折叠 隐藏此楼查看此楼

/* cairo034.c 混合操作 cairo_set_operator */
#include <cairo.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
static cairo_surface_t *surface = NULL;
struct df_canvas
{
char filename[28];
int type;
double width;
double height;
};
static void df_draw_brush (struct df_canvas const *pcanvas, cairo_operator_t op, double height)
{
cairo_t *cr;
cr = cairo_create (surface);
cairo_t *arc_cr, *rect_cr;
cairo_surface_t *arc_surface, *rect_surface;
/* 圆弧-红边黄色填充 */
arc_surface = cairo_surface_create_similar (cairo_get_target (cr), CAIRO_CONTENT_COLOR_ALPHA, 600, 370);
arc_cr = cairo_create (arc_surface);
cairo_arc (arc_cr, 300, 170, 100, 0, 2 * M_PI);
cairo_set_line_width (arc_cr, 20);
cairo_set_source_rgb (arc_cr, 0.9, 0.0, 0.0);
cairo_stroke_preserve (arc_cr);
cairo_set_source_rgb (arc_cr, 0.9, 0.9, 0.0);
cairo_fill (arc_cr);
/* 四边形 - 黑边蓝色填充 */
rect_surface = cairo_surface_create_similar (cairo_get_target (cr), CAIRO_CONTENT_COLOR_ALPHA, 600, 370);
rect_cr = cairo_create (rect_surface);
cairo_rectangle (rect_cr, 50, 50, 250, 250);
cairo_set_line_width (rect_cr, 20);
cairo_set_source_rgb (rect_cr, 0.0, 0.0, 0.0);
cairo_stroke_preserve (rect_cr);
cairo_set_source_rgb (rect_cr, 0.0, 0.0, 0.9);
cairo_fill (rect_cr);
/* 混合两个画布内容 */
cairo_set_operator (arc_cr, op); /* 设置混合操作 */
cairo_set_source_surface (arc_cr, rect_surface, 0, 0);
cairo_paint (arc_cr);
cairo_set_source_surface (cr, arc_surface, 0, height);
cairo_paint (cr);
cairo_stroke (cr);
cairo_surface_write_to_png (surface, pcanvas -> filename);
cairo_surface_destroy (arc_surface);
cairo_surface_destroy (rect_surface);
cairo_destroy (arc_cr);
cairo_destroy (rect_cr);
cairo_destroy (cr);
}
void df_init_canvas (struct df_canvas const *pcanvas)
{
surface = cairo_image_surface_create (CAIRO_FORMAT_ARGB32, (int) pcanvas -> width, (int) pcanvas -> height);
}
int main (int argc, char *argv[])
{
struct df_canvas *canvas;
canvas = (struct df_canvas*) malloc (sizeof (struct df_canvas));
strncpy(canvas -> filename, "hello.png", 28);
canvas -> type = CAIRO_SURFACE_TYPE_IMAGE;
canvas -> width = 600.0;
canvas -> height = 1500.0;
df_init_canvas (canvas);
int i;
cairo_operator_t op[] = {
CAIRO_OPERATOR_COLOR_DODGE,
CAIRO_OPERATOR_COLOR_BURN,
CAIRO_OPERATOR_HARD_LIGHT,
CAIRO_OPERATOR_SOFT_LIGHT,
CAIRO_OPERATOR_DIFFERENCE,
CAIRO_OPERATOR_EXCLUSION,
CAIRO_OPERATOR_HSL_HUE,
CAIRO_OPERATOR_HSL_SATURATION,
CAIRO_OPERATOR_HSL_COLOR,
CAIRO_OPERATOR_HSL_LUMINOSITY
};
for (i = 0; i < 5; i++)
{
df_draw_brush (canvas, op[i], i * 300.0);
}
free (canvas);
if (surface != NULL) cairo_surface_destroy (surface);
return 0;
}


2026-02-03 14:29:38
广告
不感兴趣
开通SVIP免广告
  • AutoRunAs
  • 麻婆豆腐
    11
该楼层疑似违规已被系统折叠 隐藏此楼查看此楼

/* cairo035.c 读取旋转图片内容 */
#include <cairo.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
static cairo_surface_t *surface = NULL;
struct df_canvas
{
char filename[28];
int type;
double width;
double height;
};
void df_draw_brush (struct df_canvas const *pcanvas)
{
int w, h;
cairo_surface_t* image;
cairo_t *cr;
cr = cairo_create (surface);
image = cairo_image_surface_create_from_png ("star.png"); /* 读取图片内容 */
w = cairo_image_surface_get_width (image);
h = cairo_image_surface_get_height (image);
cairo_translate (cr, 0.5 * w, 0.5 * h);
cairo_rotate (cr, 18 * M_PI / 180);
cairo_translate (cr, -0.5 * w, -0.5 * h);
cairo_set_source_surface (cr, image, 0, 0);
cairo_paint (cr);
cairo_surface_destroy (image);
cairo_surface_write_to_png (surface, pcanvas -> filename);
cairo_destroy (cr);
}
void df_init_canvas (struct df_canvas const *pcanvas)
{
surface = cairo_image_surface_create (CAIRO_FORMAT_ARGB32, (int) pcanvas -> width, (int) pcanvas -> height);
}
int main (int argc, char *argv[])
{
struct df_canvas *canvas;
canvas = (struct df_canvas*) malloc (sizeof (struct df_canvas));
strncpy(canvas -> filename, "hello.png", 28);
canvas -> type = CAIRO_SURFACE_TYPE_IMAGE;
canvas -> width = 600.0;
canvas -> height = 600.0;
df_init_canvas (canvas);
df_draw_brush (canvas);
free (canvas);
if (surface != NULL) cairo_surface_destroy (surface);
return 0;
}


  • AutoRunAs
  • 麻婆豆腐
    11
该楼层疑似违规已被系统折叠 隐藏此楼查看此楼

/* cairo036.c 剪切图片内容 */
#include <cairo.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
static cairo_surface_t *surface = NULL;
struct df_canvas
{
char filename[28];
int type;
double width;
double height;
};
void df_draw_brush (struct df_canvas const *pcanvas)
{
cairo_surface_t* image;
cairo_t *cr;
cr = cairo_create (surface);
cairo_arc (cr, 300.0, 300.0, 150.0, 0, 2 * M_PI);
cairo_clip (cr); /* 以上内容做剪切路径 */
cairo_new_path (cr);
image = cairo_image_surface_create_from_png ("star.png"); /* 读取图片内容 */
cairo_scale (cr, 1.1, 1.1);
cairo_set_source_surface (cr, image, 0, 0);
cairo_paint (cr);
cairo_surface_destroy (image);
cairo_surface_write_to_png (surface, pcanvas -> filename);
cairo_destroy (cr);
}
void df_init_canvas (struct df_canvas const *pcanvas)
{
surface = cairo_image_surface_create (CAIRO_FORMAT_ARGB32, (int) pcanvas -> width, (int) pcanvas -> height);
}
int main (int argc, char *argv[])
{
struct df_canvas *canvas;
canvas = (struct df_canvas*) malloc (sizeof (struct df_canvas));
strncpy(canvas -> filename, "hello.png", 28);
canvas -> type = CAIRO_SURFACE_TYPE_IMAGE;
canvas -> width = 600.0;
canvas -> height = 600.0;
df_init_canvas (canvas);
df_draw_brush (canvas);
free (canvas);
if (surface != NULL) cairo_surface_destroy (surface);
return 0;
}


  • AutoRunAs
  • 麻婆豆腐
    11
该楼层疑似违规已被系统折叠 隐藏此楼查看此楼

/* cairo037.c 重复图片 */
#include <cairo.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
static cairo_surface_t *surface = NULL;
struct df_canvas
{
char filename[28];
int type;
double width;
double height;
};
void df_draw_brush (struct df_canvas const *pcanvas)
{
int w, h;
cairo_surface_t *image;
cairo_pattern_t *pattern;
cairo_matrix_t matrix;
cairo_t *cr;
cr = cairo_create (surface);
image = cairo_image_surface_create_from_png ("star.png"); /* 读取图片内容 */
w = cairo_image_surface_get_width (image);
h = cairo_image_surface_get_height (image);
pattern = cairo_pattern_create_for_surface (image);
cairo_pattern_set_extend (pattern, CAIRO_EXTEND_REPEAT);
cairo_translate (cr, 0.5 * w, 0.5 * h);
cairo_rotate (cr, 18 * M_PI / 180);
/* cairo_scale (cr, 1.2, 1.2); */
cairo_translate (cr, -0.5 * w, -0.5 * h);
cairo_matrix_init_scale (&matrix, 8.0, 12.0);
cairo_pattern_set_matrix (pattern, &matrix);
cairo_set_source (cr, pattern);
cairo_rectangle (cr, 100, 100, 400.0, 700.0);
cairo_fill (cr);
cairo_surface_destroy (image);
cairo_pattern_destroy (pattern);
cairo_surface_write_to_png (surface, pcanvas -> filename);
cairo_destroy (cr);
}
void df_init_canvas (struct df_canvas const *pcanvas)
{
surface = cairo_image_surface_create (CAIRO_FORMAT_ARGB32, (int) pcanvas -> width, (int) pcanvas -> height);
}
int main (int argc, char *argv[])
{
struct df_canvas *canvas;
canvas = (struct df_canvas*) malloc (sizeof (struct df_canvas));
strncpy(canvas -> filename, "hello.png", 28);
canvas -> type = CAIRO_SURFACE_TYPE_IMAGE;
canvas -> width = 600.0;
canvas -> height = 900.0;
df_init_canvas (canvas);
df_draw_brush (canvas);
free (canvas);
if (surface != NULL) cairo_surface_destroy (surface);
return 0;
}


  • AutoRunAs
  • 麻婆豆腐
    11
该楼层疑似违规已被系统折叠 隐藏此楼查看此楼

/* cairo038.c 镜像图片 */
#include <cairo.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
static cairo_surface_t *surface = NULL;
struct df_canvas
{
char filename[28];
int type;
double width;
double height;
};
void df_draw_brush (struct df_canvas const *pcanvas)
{
int w, h;
cairo_surface_t *image;
cairo_pattern_t *pattern;
cairo_matrix_t matrix;
cairo_t *cr;
cr = cairo_create (surface);
image = cairo_image_surface_create_from_png ("star.png"); /* 读取图片内容 */
w = cairo_image_surface_get_width (image);
h = cairo_image_surface_get_height (image);
pattern = cairo_pattern_create_for_surface (image);
cairo_pattern_set_extend (pattern, CAIRO_EXTEND_REFLECT); /* CAIRO_EXTEND_PAD */
cairo_translate (cr, 0.5 * w, 0.5 * h);
/* cairo_rotate (cr, 18 * M_PI / 180); */
/* cairo_scale (cr, 1.2, 1.2); */
cairo_translate (cr, -0.5 * w, -0.5 * h);
cairo_matrix_init_scale (&matrix, 1.0, 4.0);
cairo_pattern_set_matrix (pattern, &matrix);
cairo_set_source (cr, pattern);
cairo_rectangle (cr, 0, 0, 600.0, 900.0);
cairo_fill (cr);
cairo_surface_destroy (image);
cairo_pattern_destroy (pattern);
cairo_surface_write_to_png (surface, pcanvas -> filename);
cairo_destroy (cr);
}
void df_init_canvas (struct df_canvas const *pcanvas)
{
surface = cairo_image_surface_create (CAIRO_FORMAT_ARGB32, (int) pcanvas -> width, (int) pcanvas -> height);
}
int main (int argc, char *argv[])
{
struct df_canvas *canvas;
canvas = (struct df_canvas*) malloc (sizeof (struct df_canvas));
strncpy(canvas -> filename, "hello.png", 28);
canvas -> type = CAIRO_SURFACE_TYPE_IMAGE;
canvas -> width = 600.0;
canvas -> height = 900.0;
df_init_canvas (canvas);
df_draw_brush (canvas);
free (canvas);
if (surface != NULL) cairo_surface_destroy (surface);
return 0;
}


  • AutoRunAs
  • 麻婆豆腐
    11
该楼层疑似违规已被系统折叠 隐藏此楼查看此楼

/* cairo039.c 分割图片cairo_surface_map_to_image */
#include <cairo.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
static cairo_surface_t *surface = NULL;
struct df_canvas
{
char filename[28];
int type;
double width;
double height;
};
void df_draw_brush (struct df_canvas *pcanvas)
{
cairo_surface_t *image;
cairo_surface_t *gsurface;
int i;
char str[] = "0123456789";
cairo_rectangle_int_t prec = {0, 0, 64, 64};
image = cairo_image_surface_create_from_png ("boom.png"); /* 读取图片 580_64 */
for (i = 0; i < 10; i++)
{
pcanvas -> filename[5] = str[i];
prec.x = i * 64;
gsurface = cairo_surface_map_to_image (image, &prec);
cairo_surface_write_to_png (gsurface, pcanvas -> filename);
}
cairo_surface_destroy (image);
cairo_surface_destroy (gsurface);
}
void df_init_canvas (struct df_canvas const *pcanvas)
{
surface = cairo_image_surface_create (CAIRO_FORMAT_ARGB32, (int) pcanvas -> width, (int) pcanvas -> height);
}
int main (int argc, char *argv[])
{
struct df_canvas *canvas;
canvas = (struct df_canvas*) malloc (sizeof (struct df_canvas));
strncpy(canvas -> filename, "hello0.png", 28);
canvas -> type = CAIRO_SURFACE_TYPE_IMAGE;
canvas -> width = 600.0;
canvas -> height = 370.0;
df_init_canvas (canvas);
df_draw_brush (canvas);
free (canvas);
if (surface != NULL) cairo_surface_destroy (surface);
return 0;
}


  • AutoRunAs
  • 麻婆豆腐
    11
该楼层疑似违规已被系统折叠 隐藏此楼查看此楼

C语言 _ XOXO 井字游戏 Tic-Tac-Toe [开源]
http://tieba.baidu.com/p/3970342930
XOXO 井字游戏 源码下载
http://pan.baidu.com/s/1kTAcaLx
C语言 > zzgtkcairo > gtkcairo004.7z


2026-02-03 14:23:38
广告
不感兴趣
开通SVIP免广告
  • AutoRunAs
  • 麻婆豆腐
    11
该楼层疑似违规已被系统折叠 隐藏此楼查看此楼

/* cairo040.c 掩模 cairo_mask_surface */
#include <cairo.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
static cairo_surface_t *surface = NULL;
struct df_canvas
{
char filename[28];
int type;
double width;
double height;
};
void df_draw_brush (struct df_canvas *pcanvas)
{
cairo_surface_t *image;
cairo_t *cr;
image = cairo_image_surface_create_from_png ("star.png"); /* 读取图片内容 */
pcanvas -> width = cairo_image_surface_get_width (image);
pcanvas -> height = cairo_image_surface_get_height (image);
/* 创建同图片image大小一致的画布surface */
surface = cairo_image_surface_create (CAIRO_FORMAT_ARGB32, pcanvas -> width, pcanvas -> height);
cr = cairo_create (surface);
cairo_rectangle (cr, 80, 60, 220, 440); /* 长方形掩模 */
cairo_set_source_rgb (cr, 0.7, 0.5, 0.7); /* 长方形填充色 */
cairo_fill_preserve (cr);
cairo_stroke (cr);
cairo_set_source_surface (cr, image, 0, 0);
cairo_mask_surface (cr, surface,0, 0); /* 掩模操作 */
cairo_stroke (cr);
cairo_surface_write_to_png (surface, pcanvas -> filename);
cairo_surface_destroy (image);
cairo_destroy (cr);
}
void df_init_canvas (struct df_canvas const *pcanvas)
{
surface = cairo_image_surface_create (CAIRO_FORMAT_ARGB32, (int) pcanvas -> width, (int) pcanvas -> height);
}
int main (int argc, char *argv[])
{
struct df_canvas *canvas;
canvas = (struct df_canvas*) malloc (sizeof (struct df_canvas));
strncpy(canvas -> filename, "hello.png", 28);
canvas -> type = CAIRO_SURFACE_TYPE_IMAGE;
canvas -> width = 600.0;
canvas -> height = 600.0;
df_init_canvas (canvas);
df_draw_brush (canvas);
free (canvas);
if (surface != NULL) cairo_surface_destroy (surface);
return 0;
}


登录百度账号

扫二维码下载贴吧客户端

下载贴吧APP
看高清直播、视频!
  • 贴吧页面意见反馈
  • 违规贴吧举报反馈通道
  • 贴吧违规信息处理公示
  • 首页 上一页 1 2 3
  • 52回复贴,共3页
  • ,跳到 页  
<<返回c语言吧
分享到:
©2026 Baidu贴吧协议|隐私政策|吧主制度|意见反馈|网络谣言警示