c - 如何使用 GTK/Cairo 将多个 PNG 合成为单个 PNG

标签 c animation graphics gtk cairo

我对 GTK 有点陌生,对开罗也很陌生。我的任务是创建一个应用程序,需要将 PNG 作为背景,并将包含字母和数字的多个 PNG 文件合成到背景 PNG 上,这样我最终得到一个可以转换、旋转、缩放的 PNG 文件等等。有什么我可能觉得有用的提示、教程、代码示例吗?与 GTK 的情况一样,对于尝试做比绘制形状更复杂的事情的初学者来说,Cairo 文档似乎有些缺乏。

最佳答案

看一下这个简单的例子。它仅使用开罗:

#include <cairo.h>

int main()
{
    //Load a few images from files
    cairo_surface_t *surf1 = cairo_image_surface_create_from_png("a.png");
    cairo_surface_t *surf2 = cairo_image_surface_create_from_png("b.png");

    //Create the background image
    cairo_surface_t *img = cairo_image_surface_create(CAIRO_FORMAT_ARGB32, 100, 100);

    //Create the cairo context
    cairo_t *cr = cairo_create(img);

    //Initialize the image to black transparent
    cairo_set_source_rgba(cr, 0,0,0, 1);
    cairo_paint(cr);

    //Paint one image
    cairo_set_source_surface(cr, surf1, 0, 0);
    cairo_paint(cr);

    //Paint the other image
    cairo_set_source_surface(cr, surf2, 50, 50);
    cairo_paint(cr);

    //Destroy the cairo context and/or flush the destination image
    cairo_surface_flush(img);
    cairo_destroy(cr);

    //And write the results into a new file
    cairo_surface_write_to_png(img, "result.png");

    //Be tidy and collect your trash
    cairo_surface_destroy(img);
    cairo_surface_destroy(surf1);
    cairo_surface_destroy(surf2);

    return 0;

}

关于c - 如何使用 GTK/Cairo 将多个 PNG 合成为单个 PNG,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10983739/

相关文章:

c - 我的 makefile 有什么问题?我收到 "undefined reference"错误

javascript - 设置 Canvas 缩放/缩放原点

qt - 在具有反转 y 轴的 QPainter 上绘制 QImage

c - C中的链表;删除()和搜索()

需要 C 标识符吗?

android - AndEngine 动画之间的时长

java.lang.RuntimeException : Unknown layout animation name: set

java - 如何绘制纹理并使用VBO?

java - Android - 在 ImageView 上绘制图片

c - 结构在另一个结构中的使用