staying within boundaries of image?
Posted
by codefail
on Stack Overflow
See other posts from Stack Overflow
or by codefail
Published on 2010-04-19T20:44:56Z
Indexed on
2010/04/19
20:53 UTC
Read the original article
Hit count: 206
So I am to loop through copyFrom.pixelData and copy it into pixelData.
I realize that I need to check the conditions of i and j, and have them not copy past the boundaries of pixelData[x][y],
I need another 2 loops for that? I tried this, but was getting segmentation fault.. Is this the right approach?
void Image::insert(int xoff, int yoff, const Image& copyFrom, Color notCopy)
{
for (int x = xoff; x < xoff+copyFrom.width; x++) {
for (int y = yoff; y < yoff+copyFrom.height; y++) {
for (int i = 0; i<width; i++){
for (int j = 0; j<height; j++){
if (copyFrom.pixelData[i][j].colorDistance(notCopy)>20 )
pixelData[x][y]=copyFrom.pixelData[i][j];
}
}
}
}
}
© Stack Overflow or respective owner