views:

43

answers:

1

Basically I would like to convert a bitmap to a png using libpng but rather than outputting it to a FILE* I would like to output it to a char*. I have already seen this related post but I don't see where the bitmap data is actually used. Any help would be appreciated.

+3  A: 

Use the png_set_write_fn function to redirect writes to your own function; this function, which you need to write, can store the output in any way you want.

See the documentation at http://www.libpng.org/pub/png/libpng-manual.txt

Mark Ransom
Great, thanks for the help. I finally solved it here is my solution in case anyone else is as much of a noob as me:first set the your row_pointers so each row_pointer points to a row in your bitmap. (row_pointers[i] = bitmap[i*bitmap_width*3], 3 if it's an RGB bitmap).Then set the rows:png_set_rows( png_ptr, info_ptr, row_pointers );Then call:png_set_write_fn( ... )And finally call your write_fn by calling:png_write_png( ... )
dlee123