How do i make a new image file

i know how to save a PImage as a png but i have to overwrite an existing file. can i manually create a new png file in my data folder and then write a PImage to it?

if i just try to do PImage.save(filename) it tells me i need an “absolute path” which i’m interpreting as a pre-existing file to write over. i know there’s a way to save a screenshot of the entire canvas, how can i do this with just a PImage file?

1 Like

You can save the screen with saveFrame(String+".dataType");

//Examples
saveFrame("image.png"); //saves the screen as image.png
saveFrame("imageNumber"+counter+".jpg"); //saves the screen as a imageNumber<int value>.jpg
saveFrame("frames/frame#####.jpeg"); 
//saves frame in the newly created frames folder, with the current frameCount
//replacing the ##### ; so frame 123 would look like this: frames folder > frame00123.jpeg

This means that you can actually customize the string (or use the default function of processing to replace the ### with frameCount.

Hello,

My efforts:

PImage photo1, photo2;

void setup() 
  {
  size(100, 100);
  photo2 = createImage(50, 50, RGB);
  photo2.save("\\data\\PImage2.png");
  
  photo1 = loadImage("PImage1.png");
  photo1.resize(50, 50);
  photo1.save("\\data\\PImage2.png");
  
  photo2 = loadImage("PImage2.png");
  }

void draw() 
  {
  image(photo2, 0, 0);
  }

References:

PImage.png used was from references:

PImage

:)

1 Like

what does this do? Is it just the normal “data/…”?

There is a comment about escape sequence and the \\ here:
String / Reference / Processing.org

This saves it to the data folder otherwise it just saved it to sketch folder.

This works also:

PImage photo1, photo2;

void setup() 
  {
  size(100, 100);
  photo2 = createImage(50, 50, RGB);
  photo2.save("/data/PImage2.png");
  
  photo1 = loadImage("PImage1.png");
  photo1.resize(50, 50);
  photo1.save("/data/PImage2.png");
  
  photo2 = loadImage("PImage2.png");
  }

void draw() 
  {
  image(photo2, 0, 0);
  }

:)

i know how to save a screenshot, how do i save a PImage without drawing it onto the screen first

i’ve been trying to use PImage.save(), don’t you need to already have a file that’s called that? i want to make new image files and i can’t do that with save because it needs an ‘absolute path’

essentially i’m doing image processing to change the colors of images- but i don’t want to have to do that every time because it’s slow so i wan’t to save each new color version of the image file. but i can’t do out.save(“data/”+name); because name isn’t an ‘absolute path’- it’s a variable

Try these added to your PImage file name:

println (dataPath(""));
println (sketchPath(""));

:)

2 Likes

oh wow that totally worked, thanks!

1 Like