Objectives:
/* Method to return a cropped image
* @params x, y is the upper left hand corner of the sub-image
* @param w is the width of the sub-image
* @param h is the height of the sub-image
* @return a the sub-image at (x,y) of size w by h
*/
public Picture crop(int x, int y, int w, int h){
Picture result = new Picture(w,h);
Pixel pixel;
for (int i = 0; i<w; i++) {
for (int j=0; j<h; j++) {
pixel = result.getPixel(i,j);
pixel.setColor(this.getPixel(i+x,j+y).getColor());
}
}
return result;
}
Add
this method to the Picture class and try it out. Make sure you
understand how this code works! Why are we getting pixel (i+x,j+y)
from the original picture and then changing the pixel at (i,j) in the
resulting picture?
| Assignment: Write a method for Picture that flips a picture over so that things that were on the left are now on the right. You will want to create a new picture and copy the pixels from the passed-in picture to the new picture. Return the new picture. This is NOT the same as the mirror example in the textbook. I want the entire picture flipped and displayed as a single image. |
| Assignment: Write a method for Picture that overlays one picture on top of another picture. It should not modify "this" picture but instead make a copy of "this" into a resulting picture which will serve as the base image. It will then overlay a smaller picture, smallPic, at with its upper left corner positioned at (x,y) in the base image. public Picture overlay(Picture smallPic, int x, int y) |
| Assignment: Write a method for Picture that crops a triangluar region of a picture given the x,y coordinates of the upper left corner in the original picture and the height of the cropped region. You should return a new picture rather than modifying the orginal, "this", picture. public Picture triangleCrop(int x, int y, int h)
|
| Assignment: Write a method for Picture that squishes a picture vertically (or horizontally). Hint: Copy every other row (or column) |
| Assignment: Write a program Collage.java which contains a main program to create a collage of images. Your collage should contain at least 3 images. You should use overlay and any other of the picture methods that we have created or are in the textbook.
|