Py5Image.pixels[]

The pixels[] array contains the values for all the pixels in the image.

Examples

example picture for pixels[]
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
def setup():
    global tower
    tower = py5.load_image("tower.jpg")
    dimension = tower.width * tower.height
    tower.load_pixels()
    for i in range(0, dimension, 2):
        tower.pixels[i] = "#000"

    tower.update_pixels()


def draw():
    py5.image(tower, 0, 0)

Description

The pixels[] array contains the values for all the pixels in the image. These values are of the color datatype. This array is the size of the image, meaning if the image is 100 x 100 pixels, there will be 10,000 values and if the window is 200 x 300 pixels, there will be 60,000 values.

Before accessing this array, the data must loaded with the Py5Image.load_pixels() method. Failure to do so may result in a Java NullPointerException. After the array data has been modified, the Py5Image.update_pixels() method must be run to update the content of the display window.

Underlying Java field: PImage.pixels

Updated on September 11, 2021 16:51:34pm UTC