# Help me please, I can't save my images

**URL:** <https://discourse.processing.org/t/help-me-please-i-cant-save-my-images/30811>\
**Category:** Coding Questions\
**Tags:** homework\
**Created:** [June 20, 2021, 9:32am UTC](https://discourse.processing.org/t/help-me-please-i-cant-save-my-images/30811 "2021-06-20T09:32:42Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![manu1306](https://avatars.discourse-cdn.com/v4/letter/m/c57346/32.png) [@manu1306](https://discourse.processing.org/u/manu1306)\
**Post date:** [June 20, 2021, 9:32am UTC](https://discourse.processing.org/t/help-me-please-i-cant-save-my-images/30811/1 "2021-06-20T09:32:42Z")

</div>

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();

}

---

<div class="post-metadata">

**Author:** ![Chrisir](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/chrisir/32/45_2.png) [@Chrisir](https://discourse.processing.org/u/Chrisir)\
**Post date:** [June 20, 2021, 9:36am UTC](https://discourse.processing.org/t/help-me-please-i-cant-save-my-images/30811/2 "2021-06-20T09:36:50Z")

</div>

see here [saveFrame() \ Language (API) \ Processing 3+](https://www.processing.org/reference/saveFrame_.html)

---

<div class="post-metadata">

**Author:** ![manu1306](https://avatars.discourse-cdn.com/v4/letter/m/c57346/32.png) [@manu1306](https://discourse.processing.org/u/manu1306)\
**Post date:** [June 20, 2021, 2:10pm UTC](https://discourse.processing.org/t/help-me-please-i-cant-save-my-images/30811/3 "2021-06-20T14:10:30Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![glv](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/glv/32/18785_2.png) [@glv](https://discourse.processing.org/u/glv)\
**Post date:** [June 20, 2021, 2:29pm UTC](https://discourse.processing.org/t/help-me-please-i-cant-save-my-images/30811/4 "2021-06-20T14:29:08Z")

</div>

Hello @manu1306 ,

_I was able to save to a PDF after reading tutorial and modifying the code:_  
_[PDF \ Libraries \ Processing.org](https://processing.org/reference/libraries/pdf/index.html)_

I was able to save to an image file using:  
_[saveFrame() \ Language (API) \ Processing 3+](https://processing.org/reference/saveFrame_.html)_

You should always link code to the source of code to credit the original authors:  
_[Dots](https://micultoma.ro/dots/)_

If you are posting code please format as a courtesy to the community:  
_[FAQ - Processing Foundation](https://discourse.processing.org/faq#format-your-code)_

There are resources (tutorials, references and examples) here:  
_[https://processing.org/](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.

`:)`

---

<div class="post-metadata">

**Author:** ![manu1306](https://avatars.discourse-cdn.com/v4/letter/m/c57346/32.png) [@manu1306](https://discourse.processing.org/u/manu1306)\
**Post date:** [June 20, 2021, 4:55pm UTC](https://discourse.processing.org/t/help-me-please-i-cant-save-my-images/30811/5 "2021-06-20T16:55:11Z")

</div>

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
