image - 使用 cairo 制作动画时修复图案
问题描述
我正在用 Cairo 为填充有图案的文本制作动画。问题是当文本被移动时,模式也被“移动”了。如何将模式固定在文本字符内?请参阅随附的两个屏幕截图。
if (pattern_filename)
{
cairo_surface_t *tmp_surf;
cairo_pattern_t *font_pattern;
tmp_surf = cairo_image_surface_create_from_png(pattern_filename);
font_pattern = cairo_pattern_create_for_surface(tmp_surf);
cairo_pattern_set_extend (font_pattern, CAIRO_EXTEND_REPEAT);
cairo_set_source(cr, font_pattern);
}
else
{
/* Draw the subtitle */
/* Set source color */
cairo_set_source_rgba( cr, font_color[0],
font_color[1],
font_color[2],
font_color[3] );
}
/* Move to proper place and paint text */
cairo_move_to( cr, posx, posy );
pango_cairo_show_layout( cr, layout );
谢谢
解决方案
默认情况下,表面图案将源表面的 (0,0) 放置在目标表面的 (0,0) 处。要更改这一点,您可以使用cairo_set_source_surface
直接将曲面设置为具有给定偏移的图案。或者,您可以像在代码中那样显式使用模式,并使用 and 设置一些转换cairo_matrix_init_translate
矩阵cairo_pattern_set_matrix
。
推荐阅读
- ffmpeg - 如何在树莓派 4B 上启用对 H.264 编码的硬件支持
- c# - 有没有办法阻止 EF 插入 SQL Server 计算列?
- python - 简单聚类算法的numpy实现
- android - 如何将安卓应用程序连接到树莓派?
- .net - Automapper 将平面模型的列表映射到具有内部列表的复杂实体
- c# - WebRequest 预期保持活动的连接被服务器关闭
- google-cloud-firestore - 如何通过云函数读取记录在 Firestore 字段中的长值
- python - 如何在 django 模板中打印查询集字典
- python - Flask-Marshmallow AttributeError: List Object has no Attribute 'data'
- docker - 在 docker 中调用 iptables 导致“操作不支持”