setRegion method
Copies the given image
into this PImage at the given (x
,y
).
Any pixels in image
that exceeds the available space in this PImage
are ignored.
The given (x
,y
) must sit within the bounds of this PImage.
Implementation
void setRegion({
required PImage image,
int x = 0,
int y = 0,
}) {
if (x < 0) {
throw Exception("x must be >= 0: $x");
}
if (x >= width) {
throw Exception("x must be < this image's width - width: $width, y: $y");
}
if (y < 0) {
throw Exception("y must be >= 0: $y");
}
if (y >= height) {
throw Exception("y must be < this image's height - height: $height, y: $y");
}
for (int destX = x; (destX - x) < image.width && destX < this.width; x += 1) {
for (int destY = y; (destY - y) < image.height && destY < this.height; y += 1) {
set(destX, destY, image.get(destX - x, destY - y));
}
}
}