绘制的水印图片,可以添加到应用程序。我是添加到gedit上的(GTK3.0)
#include <cairo.h>
#include <math.h>
cairo_surface_t *surface;
cairo_t *cr;
void clear_surface (void)
{cairo_t *cr;cr = cairo_create (surface);cairo_set_source_rgb (cr, 1, 1, 1); /* 白色 */cairo_paint (cr);cairo_destroy (cr);
}int main(int argc, char *argv[])
{int width = 0, height = 0;surface = cairo_image_surface_create(CAIRO_FORMAT_ARGB32, 340, 80);//创建一个图像外观cr = cairo_create(surface); cairo_select_font_face(cr, "serif", CAIRO_FONT_SLANT_NORMAL, CAIRO_FONT_WEIGHT_BOLD);//设置字体cairo_set_font_size(cr, 25.0);//设置字体大小clear_surface();//设置背景色为白色cairo_move_to(cr, 10.0, 30.0);//从10 30 开始绘制cairo_set_source_rgb (cr, 0.9, 0.9, 0.9); /* 设置字体颜色 */cairo_show_text(cr, "机密文件!请勿外传!");cairo_destroy(cr);cairo_surface_write_to_png(surface, "timg.png");cairo_surface_destroy(surface);cairo_surface_t *image;cairo_pattern_t *pattern;surface = cairo_image_surface_create(CAIRO_FORMAT_ARGB32, 1440, 900);cr = cairo_create(surface);image = cairo_image_surface_create_from_png ("timg.png");width = cairo_image_surface_get_width (image);height = cairo_image_surface_get_height (image);pattern = cairo_pattern_create_for_surface (image);cairo_pattern_set_extend (pattern, CAIRO_EXTEND_REPEAT);//平铺 cairo_rotate (cr, M_PI / 4);//旋转多少cairo_scale (cr, 2, 2);//x指宽度缩放倍数,y指高度缩放的倍数cairo_translate (cr, -(width+110), -(height+420));cairo_set_source (cr, pattern);cairo_rectangle (cr, 0, 0, 1440, 900);//绘制一个矩形,起点是0,0,长1440,宽900 cairo_fill (cr);cairo_destroy(cr);cairo_pattern_destroy (pattern);cairo_surface_destroy (image);cairo_surface_write_to_png(surface, "timg.png");cairo_surface_destroy(surface);return 0;
}
Makefile:
tupian: shilic -g -o $@ $< -lm `pkg-config --cflags --libs gtk+-3.0`
好了生成的图片就可以用了,下图是gedit的水印效果。
本文发布于:2024-01-30 01:35:00,感谢您对本站的认可!
本文链接:https://www.4u4v.net/it/170654970418302.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
留言与评论(共有 0 条评论) |