Reputation: 1607
I'm trying to write a PNG file from an image that can be grayscale (8bits*1componant) or rgb (8bits*3componants) with libpng
in C
.
I read the manual and wrote this piece of code that doesn't work :-/
/* 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);
Nothing is written into the image, and I don't understand why.
img.data
points to the image datas (interlaced in the case of RGB format)
Upvotes: 2
Views: 4679
Reputation: 2445
The documentation says you are supposed to use png_write_end, see "Finishing a sequential write" section in http://www.libpng.org/pub/png/libpng-1.2.5-manual.html. There are plenty of examples out there (eg http://zarb.org/~gc/html/libpng.html)
Upvotes: 1