Answering myself, if somebody find a better solution please answer and I will change my accepted answer.
The only reliable way to access the render result pixels is this:
Save the actual value of bpy.data.scenes["Scene"].render.filepath
to a local variable
Set bpy.data.scenes["Scene"].render.filepath
to something to avoid overwriting any previous render, for example "//temp." + str(time.time()) + ".png"
. 1 and 2 can be ignored if you don't care of any previous render.
Call bpy.ops.render.render(write_still=True)
. write_still
set to true
will cause the file to be immediately written to disk.
Create a new image and load that file from disk, or use an existing image reserved for this purpose in your blend file and set its filepath and then reload.
Do what you need to do with the loaded image pixels.
Remove the loaded image, except you have a good reason to keep it in the blend file.
Restore the original value of bpy.data.scenes["Scene"].render.filepath
Brief: the only reliable way to access pixel data of a render is to render it, save to disk immediately, recover from disk, read pixel data.
At the time of writing this, Blender version is 2.68.
ImDisk Toolkit
. $\endgroup$ – Mike de Klerk Apr 9 '20 at 7:10