Skip to content

loadPixels()

Loads the current value of each pixel on the canvas into the pixels array.

loadPixels() must be called before reading from or writing to pixels.

Examples

loadPixels example 1

local img
function setup() 
  size(100, 100)
  windowTitle("loadPixels example")
  -- Load the image.
  img = loadImage('assets/rockies.jpg')

  -- Display the image.
  image(img, 0, 0, 100, 100)

  -- Get the pixel density.
  local d = pixelDensity()
  print(d)
  -- Calculate the halfway index in the pixels array.
  local halfImage = 4 * (d * width) * (d * height / 2)
print(4 * width * (height / 2))
  -- Load the pixels array.
  loadPixels()

  -- Copy the top half of the canvas to the bottom.
  for i=1,halfImage do
    pixels[i + halfImage] = pixels[i]
  end

  -- Update the canvas.
  updatePixels()

  describe('Two identical images of mountain landscapes, one on top of the other.')
end

Syntax

loadPixels()