You were right, Liudr... when I drew the original image, it had also been changed. So it was just the reference being passed. So I incorporated your suggestion and Ramin's suggestion, and here is a method which passes a PImage and returns a PImage, allowing you to draw whatever you want on it in the method (in this case just drawing a rect on it). This is just what I need as I want to create an array of images and draw on them all, but without actually drawing them to the screen initially. So I'll pass them all down to the method which will alter them, and then I can store them in the array.
Thanks for all your help, guys. Very useful indeed.
Code:PImage img;
void setup()
{
size(640, 480);
img= loadImage("gray.jpg"); //just an image with all grey pixels
PImage img2= alterImage(img);
image(img2,0,0);
}
void draw()
{
}
PImage alterImage(PImage i1)
{
PGraphics pg=createGraphics(640,480,P2D);
pg.beginDraw();
pg.copy(i1, 0, 0, 640, 480, 0, 0, 640, 480);
pg.fill(0,255,0);
pg.rect(width/2, height/2, 50, 50);
pg.endDraw();
PImage i2=createImage(640,480, RGB);
i2.copy(pg,0,0,640,480,0,0,640,480);
return i2;
}