orlp
orlp

Reputation: 117681

libpng load file from memory buffer

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.

Upvotes: 12

Views: 9932

Answers (1)

orlp
orlp

Reputation: 117681

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.

Upvotes: 12

Related Questions