How to acces raw pixels data of rendered image?

Hi everyone !

My goal is to create an add-on that saves a rendered image in a QOI file format for a school project

https://qoiformat.org/

But for this i need to acces the raw pixels data (bytes would be perfect) straight from Blender.

i’ve pocked around the python API and tried using bpy.data.images[‘Render Result’] to get just that but nope, its not working (it seems to be empty even after i rendered smthg ???)

Maybe i’m doing something wrong ? it’s been weeks and i still can’t find the answer. Either what i find is not actually related to my problem either its dating all the way back to 2010 or something.

I really need someone to explain to me how all of this works, or at least, to point me in the right direction. Maybe it’s a quirk of the Python API i’m not aware of ?

Anything is appriciated at this point haha !

A work-around i’m currently using is to use the viewer node but the color depth is only 8 bits, where blender can render 16 and 32bits images so i’m losing information

Cheers !

Hi!

You can’t access pixels from render results directly, but with the recent changes to the gpu module you can read the pixels into a bgl.Buffer that uses an underlying numpy array. From that point on coercing it into a stream of bytes shouldn’t be a problem.

See the method described here https://blender.stackexchange.com/a/248543.

1 Like