I tried looking through the libpng documentation, but didn't find what I was looking for.
I have a PNG file fully in a memory buffer, how can I load this file (apart from the obvious solution of creating a temporary file)?
Not sure if it's relevant, but I'm calling libpng from Python using ctypes.
LibPNG reads the image line by line, and in order to work with the read function, libPNG requires an array of pointers, where each sequential pointer, points to the start of each new line or row of pixels in your buffer.
The second parameter is a pointer to the datablock where we have to put our data, and the third parameter is the amount of data we should put in the data block (and thus the size of the block). First, let’s tell libPNG to use our readfunction to get the data.
It contains a “includes”, a “libs” and a “Manifest” folder. Unpack the package somewhere where you can find it Go into your visual studio and open your kick-ass project that you want to use libpng in. Select the project settings and open the property page.
This build script will tell the NDK tools to build a static library called libpng that is linked against zlib, which is built into Android. It also sets up the right variables so that we can easily import this library into our own projects, and we won’t even have to do anything special because the right includes and libs are already exported.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With