0

I have the following blender script to get the pixel data of a render

project_path = os.path.dirname(bpy.data.filepath)
render_path = project_path + "/textures/" + collection.name
bpy.context.scene.render.filepath = render_path + ".png"
bpy.ops.render.render(write_still=True)
image = bpy.data.images.load(bpy.context.scene.render.filepath)
pixels = [int(value * 255) for value in image.pixels]
os.remove(bpy.context.scene.render.filepath)

You can see I'm saving the render into a png file which later I load again so I can get the pixel data.

This is not efficient, could be possible to just get the pixel data without saving it into a file?

  • https://blender.stackexchange.com/questions/269494/how-to-access-render-result-image-layers-python or https://blender.stackexchange.com/questions/2170/how-to-access-render-result-pixels-from-python-script – lemon Jan 30 '24 at 07:20
  • @lemon all those solutions require to render the result into a file, I just want to render without writing a file, I just need the pixel data in my script. Saving to a file and then parsing a png again is quite slow – ellipticaldoor Jan 30 '24 at 07:30
  • sorry the first link is an error. The second one may work: https://blender.stackexchange.com/a/23309/19156 – lemon Jan 30 '24 at 07:37
  • this looks a bit hacky, there is no official way? – ellipticaldoor Jan 30 '24 at 07:42
  • 1
    'Render result' is still empty, afaik... – lemon Jan 30 '24 at 07:52
  • you could try this one also https://blender.stackexchange.com/a/248543/19156 – lemon Jan 30 '24 at 07:59

0 Answers0