I'm writing a program which has a method to transform images in certain ways - this method takes a PImage as a parameter, and returns a PImage (this is something I was discussing on here earlier).
This works, but the image is gradually zoomed and blurred over time with repeated copying- see the code below. I'm guessing in one of the copying steps the size does not match up correctly. But as all the copying starts at 0,0, and has size 640, 480, I can't see where the unfaithful copying is taking place. Can anyone spot anything obvious? Thanks....
(I have just taken out the relevant part of the program to isolate the problem here):
Code:PImage currentimg;
void setup()
{
size(640, 480);
frameRate(3);
noStroke();
initialise();
}
void draw()
{
currentimg=transform(currentimg);
image(currentimg,0,0);
}
void initialise()
{
fill(random(100), random(100), random(100));
rect(width/2,height/2, width, height);
fill(random(100), random(100), random(100));
rect(random(width), random(height), random(200), random(200));
fill(random(100), random(100), random(100));
rect(random(width), random(height), random(200), random(200));
fill(random(100), random(100), random(100));
ellipse(random(width), random(height), random(200), random(200));
fill(random(100), random(100), random(100));
ellipse(random(width), random(height), random(200), random(200));
currentimg=get(0, 0, 640, 480);
}
PImage transform(PImage img)
{
PGraphics pg=createGraphics(640,480,P2D);
pg.beginDraw();
pg.copy(img, 0, 0, 640, 480, 0, 0, 640, 480);
pg.endDraw();
PImage i2=createImage(640,480, RGB);
i2.copy(pg,0,0,640,480,0,0,640,480);
return i2;
}