How do I export an image to a transparent background

Hi there -
I have made a simple design .
I would like to modify this code to save this image as a PNG with a transparent background.
Can anyone help me? Thanks!

<
PImage pic;

void setup(){
size(600,1000);
background(0,0);
pic=loadImage(“N1.png”);
pic.resize(width,0);
}

int spacing=6;

void draw(){
for(int x=spacing;x<width;x+=spacing){
for(int y=spacing;y<height;y+=spacing){
color c=pic.get(x,y);
fill(c);
noStroke();
ellipse(x,y,spacing0.7,spacing0.7);
}
}
}
void keyPressed() {
if (key == ‘s’ || key == ‘s’) {
save(“93.png”);
}
}

Hello @W24 ,

Welcome!

Please read:

You did not format your code.

A bit of research will yield an answer!

  • Search this forum for transparent background and it will yield numerous results to help you.

  • Search this site:
    https://processing.org/
    for transparent background and it will set you on the right path.

:)

1 Like

The frame created with the draw() method does not have a transparent background so when you save it with save("93.png"); you will not get any transparent pixels. The solution is to draw to an off-screen buffer and then save the buffer. Use the createGraphics method to create the buffer then you can draw to it.

3 Likes