I found this article which describes pretty well how to read a PNG file from memory.
Summarized, you have to create a custom callback function and give it to libpng
using png_set_read_fn
. Then in that callback function you read from your memory buffer rather than a file.