Skip to content

Instantly share code, notes, and snippets.

@zeffii
Created February 26, 2014 12:30
Show Gist options
  • Save zeffii/9228682 to your computer and use it in GitHub Desktop.
Save zeffii/9228682 to your computer and use it in GitHub Desktop.
import bpy
D = bpy.data
# BlendDataImages.new(name, width, height, alpha=False, float_buffer=False)
image_object = D.images.new(name='pixeltest', width=4000, height=3000)
# image_object points to the newly created: bpy.data.images['pixeltest']
num_pixels = len(image_object.pixels)
# well, turns out pixels is a little bit of a misnomer.
print(num_pixels)
# >>> 480000
# A number 4 timeslarger than the expected 120000 pixels. It appears that
# .pixels is a list of the RGBA values of every pixel in sequence.
print( bpy.data.images['pixeltest'].file_format )
# >>> 'TARGA'
# seems to be the internal default
print(image_object.pixels[:4])
# >>> (0.0, 0.0, 0.0, 1.0)
# drawing a pixel, changing pixel content
for i in range(4):
image_object.pixels[0+i] = (1.0)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment