Create a new Java class named Lab8 and save it to your P: drive
in a file named Lab8.java. Add a main method and
make sure it compiles before you proceed.
blackAndWhite method as in
pic.blackAndWhite();it changes the picture
pic, the object to the left of the "." .
Modify your blackAndWhite method so that it doesn't modify the actual
picture object but is a function that returns a new picture that is black and white. For example the sequence:
Picture pic = new Picture(path + "sunset.jpg");
Picture pic2 = pic.blackAndWhite();
pic.repaint();
pic2.repaint();
should show both the color and black and white version of the sunset.
Picture pic = new Picture(path + "sunset.jpg");
pic.blackAndWhite().repaint();
Notice that we are calling the repaint method on the
object that is returned from blackAndWhite.
enlarge() that enlarges a picture by doubling its width and height. This method should return the new larger
picture. Here is an example of how you would call it.
Picture pic = new Picture(path + "sunset.jpg");
pic.enlarge().repaint();
shrink and enlarge are methods that return pictures what happens when we do the following? What does the picture look like?
pic.smaller().smaller().bigger().bigger().repaint();
decreaseRed() that decreases
the amount of red in the picture by a percentage that is passed as an actual argument. This method
should return a new picture. For example,
pic2 = pic.decreaseRed(1) the picture pic2 should
be a picture with all of the red in pic removed.
Calling pic2 = pic.decreaseRed(.25) should decrease the red by 25%.
flipVertical() that returns a new picture
that is the picture flipped up-side-down.
Picture pic = new Picture(path + "sunset.jpg"); pic.flipVertical().repaint();
copyRegion(x,y,width,height) that copies a region of a picture starting at the upper left coordinate (x,y) for
width and height pixels.
For example
Picture pic = new Picture(path + "fish.jpg");
pic.copyRegion(214,3,170,80).repaint();
should display a fish extracted from a larger picture.
Picture pic = new Picture(path + "comic.jpg");
pic.copyRegion(10,60,210,20).flipVertical().enlarge().decreaseRed(1).repaint();