Activity 4.69.1.
Picture Lab A8: Run to see createCollage() working.
fromRow and toRow in the outer for loop and increment them both at the end of the loop. A for loop can have more than one variable declaration and initialization and/or modification. Just separate the items with commas. The inner loop in this code uses that to create two loop variables, fromCol and a toCol which are both declared, initialized, and incremented.
public void copy(Picture fromPic,int startRow, int startCol)
{
Pixel fromPixel = null;
Pixel toPixel = null;
Pixel[][] toPixels = this.getPixels2D();
Pixel[][] fromPixels = fromPic.getPixels2D();
for (int fromRow = 0, toRow = startRow;
fromRow < fromPixels.length &&
toRow < toPixels.length;
fromRow++, toRow++)
{
for (int fromCol = 0, toCol = startCol;
fromCol < fromPixels[0].length &&
toCol < toPixels[0].length;
fromCol++, toCol++)
{
fromPixel = fromPixels[fromRow][fromCol];
toPixel = toPixels[toRow][toCol];
toPixel.setColor(fromPixel.getColor());
}
}
}
Data: flower1.jpgData: flower2.jpgData: snowflake.jpgData: butterfly.jpg
public void createCollage()
{
Picture flower1 = new Picture("flower1.jpg");
Picture flower2 = new Picture("flower2.jpg");
this.copy(flower1,0,0);
this.copy(flower2,100,0);
this.copy(flower1,200,0);
Picture flowerNoBlue = new Picture(flower2);
flowerNoBlue.zeroBlue();
this.copy(flowerNoBlue,300,0);
this.copy(flower1,400,0);
this.copy(flower2,500,0);
this.mirrorVertical();
this.show();
}
createCollage method below.

copyPartial that adds parameters to allow you to copy just part of the fromPic. You will need to add parameters that specify the start row, end row, start column, and end column to copy from.
myCollage method that has at least three pictures (can be the same picture) copied three times with three different picture manipulations and at least one mirroring. You can use the pictures flower1.jpg, flower2.jpg, snowflake.jpg, butterfly.jpg in this lesson. To use your own images, you can fork this replit.com Swing projecthttps://replit.com/@BerylHoffman/Picture-Labhttps://replit.com/@jds7184/PictureLab