Sign in to follow this  
Prune

fstream and libpng

Recommended Posts

Prune    224
How do I do it? The damn libpng uses a FILE *. Is there any way to get a compatible file pointer from an ifstream? [Edited by - Prune on October 27, 2008 11:54:00 AM]

Share this post


Link to post
Share on other sites
the_edd    2109
You have to write a new input source. It's all in the libpng docs.

Alternatively, I have a C++ wrapper that makes this incredibly easy. You can get the source code from here:

pngxx. You'll need this support library, too.

EDIT: you'll need Mercurial to get the code, at least until I release some zip files.

I haven't put together any docs yet (hopefully soon, though) but here's the basic idea:


std::vector<unsigned char> raster;
std::ifstream source("lalala.png"); // could be any istream

imagexx::raster_details d = pngxx::read_image(source, back_inserter(raster));

// Now query the details of the raster by looking at d





It also supports reading from an arbitrary input iterator pair, or you could give the filename directly. There are a bunch of iterator adaptors too, to allow you to read it in to any pre-existing image containers. Just ask if you want to know more.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this