我试图从图像中写入一个PNG文件,该图像可以是libpng中的灰度(8bits*1 componant)或rgb(8bits*3 componants)。
我读了手册,写了一段不起作用的代码:-/

/* 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);

图像上什么也没写,我不明白为什么。
C指向图像数据(在RGB格式的情况下隔行扫描)

最佳答案

文档说明您应该使用png-write-end,请参见http://www.libpng.org/pub/png/libpng-1.2.5-manual.html中的“完成顺序写入”部分。
有很多例子(如http://zarb.org/~gc/html/libpng.html

关于c - 用libpng用C编写灰度或RGB的PNG,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/18010613/

10-12 23:18