General scale down method
/**
* Method to create a new picture 1/2 the size of the original
* @return the 1/2 sized picture
/
public Picture scaleDown()
{
Picture targetPicture = new Picture(this.getWidth()/2 + 1,this.getHeight()/2 + 1);
Pixel sourcePixel = null;
Pixel targetPixel = null;
// loop through the columns
for (int sourceX = 0, targetX=0;
sourceX < this.getWidth();
sourceX+=2, targetX++)
{
// loop through the rows
for (int sourceY=0, targetY=0;
sourceY < this.getHeight();
sourceY+=2, targetY++)
{
sourcePixel = this.getPixel(sourceX,sourceY);
targetPixel = targetPicture.getPixel(targetX,targetY);
targetPixel.setColor(sourcePixel.getColor());
}
}
// show the resulting picture
targetPicture.show();
return targetPicture;
}
Link to this Page