Part VIII

Creating a Collage

You can copy one picture to another by copying the color from the pixels in one picture to the pixels in the other picture. To do this you will need to keep track of the row and column information for both the picture you are copying from and the picture you are copying to, as shown in the following copy method. The easiest way to do this is to declare and initialize both a 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. Note that the inner loop has both a fromCol and a toCol declared, initialized, and incremented.


You can create a collage by copying several small pictures onto a large picture. You can also add in other manipulations, like zeroBlue, before copying the picture. Or you could use one of your mirror methods after collaging in some other pictures. There is an example in the Picture class in the method createCollage.


One important method to notice is the write method. "this.write("filename.jpg");" would write a new file to your images folder. Be sure to include ".jpg" so your computer knows the file type and will therefore be able to open the file. You can also make the file save to a different location by writing in the full location. For example, you could write something like "c:\temp\collage.jpg."


The following method shows how to create a simple collage using the copy method.

Questions

  • Create a new copy method that takes in parameters that will allow you to add just a portion of one picture to another picture.. You don't need to change the name of the method - whether or not the client code includes parameters will be the thing that tells java which method to use. Copy/paste your new copy method.
  • Write a myCollage method that has at least three different methods copied into a main picture. You should use at least three different picture manipulations, including both color alterations and mirroring. Don't forget to include code that writes the final image into a file on your computer. Copy/paste your code and the collage that you created.