Is it possible to have a rectangular selection tool applied to a PImage (to get pixels and copy them)?
in
Programming Questions
•
1 years ago
I am trying to create a rectangular selection tool that draws the upper left corner of the rectangle when the mouse is first clicked and then the bottom right corner of the rectangle when the mouse is next released. I've got this so far but the top left corner is always reading as (0, 0) for some reason.
PImage imageA;
Pictures selectPartOfImage;
void setup () {
size (screen.width, screen.height);
background (230);
imageA=loadImage ("imageA.jpg");
selectPartOfImage = new Pictures (color(0, 0, 0, 0), 0, 0, 0, 0);
}
void draw () {
background (230);
image (imageA, 0, 0, width/4, height/4);
selectPartOfImage.select();
selectPartOfImage.mouseReleased();
} // end of draw
class Pictures {
color clr;
int x1, y1, x2, y2;
Pictures (color tempClr, int tempx1, int tempy1, int tempx2, int tempy2) {
clr=tempClr;
x1=tempx1;
y1=tempy1;
x2=tempx2;
y2=tempy2;
} // end of the constructor
void select () {
if (mousePressed) {
int x1=mouseX;
int y1=mouseY;
}
}
void mouseReleased() {
int x2=mouseX;
int y2=mouseY;
fill (0, 0, 0, 0);
rect (x1, y1, x2, y2);
}
} // end class
PImage imageA;
Pictures selectPartOfImage;
void setup () {
size (screen.width, screen.height);
background (230);
imageA=loadImage ("imageA.jpg");
selectPartOfImage = new Pictures (color(0, 0, 0, 0), 0, 0, 0, 0);
}
void draw () {
background (230);
image (imageA, 0, 0, width/4, height/4);
selectPartOfImage.select();
selectPartOfImage.mouseReleased();
} // end of draw
class Pictures {
color clr;
int x1, y1, x2, y2;
Pictures (color tempClr, int tempx1, int tempy1, int tempx2, int tempy2) {
clr=tempClr;
x1=tempx1;
y1=tempy1;
x2=tempx2;
y2=tempy2;
} // end of the constructor
void select () {
if (mousePressed) {
int x1=mouseX;
int y1=mouseY;
}
}
void mouseReleased() {
int x2=mouseX;
int y2=mouseY;
fill (0, 0, 0, 0);
rect (x1, y1, x2, y2);
}
} // end class
1