我正在尝试从libpng
中C
的灰度(8位* 1分量)或rgb(8位* 3分量)的图像中写入PNG文件。
我阅读了手册并编写了一段不起作用的代码: - /
/* writing the image */
png_byte *row_pointers[img->height];
int h;
for (h = 0 ; h < img->height ; h++)
{
row_pointers[h] = img->data+h*img->width*image_components;
}
png_write_image(png_ptr, row_pointers);
没有任何内容写入图像,我不明白为什么。
img.data
指向图像数据(在RGB格式的情况下隔行扫描)
答案 0 :(得分:1)
文档说您应该使用png_write_end,请参阅http://www.libpng.org/pub/png/libpng-1.2.5-manual.html中的“完成顺序写入”部分。 那里有很多例子(例如http://zarb.org/~gc/html/libpng.html)