Tell me more ×
Blender Stack Exchange is a question and answer site for people who use Blender to create 3D graphics, animations, or games. It's 100% free, no registration required.

Render Result exists in bpy.data.images["Render Result"] but it contains no data.

Also bpy.data.images["Render Result"].size[0] is 0, even if the render shows as an image in the UV/Image Editor with a width of 1366.

Maybe the render result cannot be accessed as an image or I missing some update or refresh call somewhere but I can't find such a thing in the 2.68 API documentation.

Any tip in the correct direction appreciated.

share|improve this question

2 Answers

Last time I experimented with this, it was necessary to save the content of Render Result as an image to disk and then load it as a new image. Then the pixel array is accessible. Maybe this API feature can be improved, or i'm doing it wrong :)

import bpy

bpy.data.images['Render Result'].save_render("somefile.tga")
r2 = bpy.data.images.load("somefile.tga")
r2.pixels[0] = 0.2345
share|improve this answer
Thank you. Indeed, pixel data is accessible if the image has a file path and is saved first. But the render I want to read from is generated by the script (by calling bpy.ops.render()). If I render with F12, assign a file path to the render result and save, the next time I call bpy.ops.render() Blender generated a new image called "Render Result.001", It does not use the "Render Result" image any more. – Hatoru Hansou Aug 6 at 21:09
yeah, i'm going to avoid suggesting that you keep track of All images with string "Render Result" and sort them and access the last index -1, perhaps someone else can offer enlightenment. – zeffii Aug 6 at 21:14
up vote 0 down vote accepted

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:

1- Save the actual value of bpy.data.scenes["Scene"].render.filepath to a local variable

2- 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.

3- Call bpy.ops.render.render(write_still=True). write_still set to true will cause the file to be immediately written to disk.

4- 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.

5- Do what you need to do with the loaded image pixels.

6- Remove the loaded image, except you have a good reason to keep it in the blend file.

7- Restore the original value of bpy.data.scenes["Scene"].render.filepath

In resume: 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.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.