Monday, April 19, 2010

staying within boundaries of image?

Programmer Question

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];
}
}
}
}
}


Find the answer here

No comments:

Post a Comment

LinkWithin

Related Posts with Thumbnails