我正在使用 Cairo 渲染图像,但我遇到的问题是画布总是用空白绘制(没有绘制图像)。请参考我下面的代码:
int width, height, channels;
unsigned char* data = stbi_load(imagePath.c_str(), &width, &height, &channels, STBI_rgb_alpha);
int stride = cairo_format_stride_for_width(CAIRO_FORMAT_ARGB32, width);
this->imageSource = cairo_image_surface_create_for_data(data, CAIRO_FORMAT_ARGB32, width, height, stride);
free(data);
但是,如果我使用 Cairo 当前支持的功能渲染 png 文件,它运行良好,我的代码如下:
this->imageSource = cairo_image_surface_create_from_png(imagePath.c_str());