scale a background picture
in
Contributed Library Questions
•
2 months ago
I'm trying to scale a jpg that I am using for a background. I have written code, but its not working. Can someone help with this ?
PImage GSimg, bgimg;
float tolerance = 22;
PImage GSimgout;
import controlP5.*;
ControlP5 controlP5;
float scale = 0.92;
void setup() {
GSimg = loadImage("familyGreen.jpg");
GSimg.resize(700, 494);
bgimg = loadImage("Hiking.jpg");
// bgimg.resize(1050, 494);
pushMatrix();
translate(width/2,height/2);
scale(scale);
popMatrix();
size(GSimg.width, GSimg.height);
controlP5 = new ControlP5(this);
controlP5.addSlider("scale",0,50,20,20,100,30);
}
void draw() {
for (int x = 0; x < GSimg.width; x++)
{
for (int y = 0; y < GSimg.height; y++)
{
float r = red(GSimg.get(x, y));
float g = green(GSimg.get(x, y));
float b = blue(GSimg.get(x, y));
if (g > b + tolerance && g > r + tolerance)
{
GSimg.set(x, y, bgimg.get(x, y)) ;
}//end if
}//end for
}
image(GSimg, 0, 0);
save("Familymtngreenout.jpg");
}
1