gpt4 book ai didi

cairo - 无法在开罗渲染文本

转载 作者:行者123 更新时间:2023-12-04 12:48:35 26 4
gpt4 key购买 nike

我是开罗的新手,我已经阅读了其网站上的教程/文档。
现在我可以制作线条、矩形,基本上我可以渲染图像但不能渲染文本。

我正在使用以下代码

cairo_select_font_face (cr, "monospace", CAIRO_FONT_SLANT_NORMAL, CAIRO_FONT_WEIGHT_NORMAl);

cairo_set_font_size (cr, 14);

cairo_set_source_rgb (cr, 1, 1, 1);

cairo_move_to (cr, 50, 50);

cairo_show_text (cr, "Print Something");

任何人都可以指出我的错误吗?

最佳答案

与开罗邮件列表上的答案相同(似乎已在某处丢失):

你没有做错任何事(好吧,也许使用玩具文本 API,但它应该仍然有效)并且你的代码对我来说很好用。这是我测试的完整代码:

#include <cairo.h>
int main()
{
cairo_surface_t *surface = cairo_image_surface_create(CAIRO_FORMAT_ARGB32, 200, 200);
cairo_t *cr = cairo_create(surface);
cairo_surface_destroy(surface);

/* Fill everything with white */
cairo_set_source_rgb(cr, 1, 1, 1);
cairo_paint(cr);

/* Draw some text */
cairo_select_font_face (cr, "monospace", CAIRO_FONT_SLANT_NORMAL, CAIRO_FONT_WEIGHT_NORMAL);
cairo_set_font_size (cr, 14);
cairo_set_source_rgb (cr, 0, 0, 0);
cairo_move_to (cr, 0, 50);
cairo_show_text (cr, "Print Something");

cairo_surface_write_to_png(cairo_get_target(cr), "out.png");
cairo_destroy(cr);
return 0;
}

关于cairo - 无法在开罗渲染文本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13162085/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com