Help me please, I can't save my images

Hello I am new to the processing software I found a code on github but I would have liked to add the function of saving the image for each image made by the algorithm can you help me please thank you because I do not can’t save my images the code is

import processing.pdf.*;

PImage img;
PImage displayImg;

// change this to get a bigger final image
int scale = 4;
float xScreen, yScreen;
float randomPixel;

color pixelColor;

int totalPoints = 0;

void setup() {
size(600, 800);
//size(2400, 3200, PDF, “womanDots.pdf”);
background(255);

//work in Hue Saturation Brightness instead of RGB, since the image is b/w
//with a max value of 100
colorMode(HSB, 100);
fill(255);

img = loadImage(“ALE.jpg”);
displayImg = createImage(img.width * scale, img.height * scale, RGB);

//make the display image white initially
for (int i=0; i<displayImg.pixels.length; i++) {
displayImg.pixels[i] = color(0, 0, 100);
}

//this only needs to be created once
//beginRecord(PDF, “womanDots.pdf”);
createDotImage();
}

void draw() {
// we want to move the image around on the screen and see it in full even if it’s a few times larger than the canvas
rect(0, 0, width, height);

xScreen = map(mouseX, 0, width, width - displayImg.width, 0);
yScreen = map(mouseY, 0, height, height - displayImg.height, 0);

image(displayImg, xScreen, yScreen);
}

void createDotImage() {
//loop through all the pixels of the original image and create dots in a square for each of them
// how many dots depends on how bright / dark the pixel is

for (int y=0; y<img.height; y++) {
for (int x=0; x<img.width; x++) {
pixelColor = img.get(x, y);

  //now use the color information in a square that's scale*scale pixels large in the displayImg
  for (int j=0; j<scale; j++) {
    for (int i=0; i<scale; i++) {
      
      randomPixel = random(100);
      
      //pixels need to be black or white depending on whether they pass a certain threshold
      if (brightness(pixelColor) < randomPixel) {
        displayImg.set((x*scale)+i, (y*scale)+j, color(0, 0, 0));
        
        totalPoints++;
      }
    }
  }
}

}

println("Total number of points = " + totalPoints);

//image(displayImg, 0, 0);
//endRecord();

}

see here saveFrame() \ Language (API) \ Processing 3+

thank you but I tried but my image is saved all white so I do not understand what to add to my code to be able to save my processed image

Hello @manu1306 ,

I was able to save to a PDF after reading tutorial and modifying the code:
PDF \ Libraries \ Processing.org

I was able to save to an image file using:
saveFrame() \ Language (API) \ Processing 3+

You should always link code to the source of code to credit the original authors:
Dots

If you are posting code please format as a courtesy to the community:
FAQ - Processing Foundation

There are resources (tutorials, references and examples) here:
https://processing.org/

Check out the examples that come with Processing!
These are in the menu under File > Examples…>

This is your homework so I will leave this with you.

This is achievable with some work on your part.

:)

thank you very much for your advice but I tried hard but I can not please tell me what has been added to the code to be able to save my image in jpg I would have liked to be able to do it walk to pay homage to my dad by spanking a portrait of him to offer it to my grandmother thank you and sorry to bother you