Fast Pixel by Pixel Image Editing

I have an array of PImages upscaledImages[] pulled from a folder

How would I:

  • Edit Individual pixel’s based on their contents
  • Save the array of edited images, overwriting the unedited ones

All of this needs to be done in a semi-efficient manner because I am working with a lot of images

1 Like


I think this is the way to go without using any arrays :

// The number of images
int nbImages = 50;

// Go through every image
for (int i=0; i<nbImages; i++) {
  // Load it (assuming that their names are image###.png)
  String filename = "image" + i + ".png";
  PImage img = loadImage(filename);
  // Loop through every pixels
  for (int x = 0; x < img.width; x++) {
    for (int y = 0; y<img.height; y++) {
      int loc = x + y * img.width;
      // Do something with the pixel
      img.pixels[loc] = ...;
  // Override the image;


How would I get the alpha value of the pixel at img.pixels[loc]

Looking at the Processing reference is really handy :slight_smile: what you need is :

And also this nice tutorial on images and pixels by Daniel Shiffman :