CS 140 - Lab 11 Instructions

In this lab you are going to practice shrinking and enlarging pictures.

Objectives

  1. Experiment with new picture methods that change the size of a picture.

Method

Part I - Shrinking a picture

  1. Create a Java program named Lab11 that shows the gnat.jpg picture from the CS140 gallery folder.
  2. Implement the shrink method we designed in lecture today and use it on your picture above and display it. In which class and file does this method go?
  3. Shrink the picture again and show it.
  4. Have your instructor or the lab assistant check your work.

Part II - Enlarging a picture

  1. Develop a Picture method enlarge that enlarges a picture by doubling the width and height. Use the technique we discussed in class.
  2. Use your enlarge method on the picture two_fish.jpg. Show both the original picture and the enlarged picture. Look at the quality of the enlarged picture. What do you notice as compared to the original picture?
  3. In this step we're going to enlarge a picture that we previously shrunk.
    1. Show the original two_fish.jpg picture (you are probably already doing this from the step above).
    2. Shrink two_fish.jpg. (Don't bother showing it).
    3. Now re-enlarge the shrunken picture back to its original size and show it.
    4. Compare the original picture with the picture that was shrunk and then enlarged. Explain why when we shrink a picture and then enlarge it we don't get the original picture back.
    5. Look up the term pixelation on Wikipedia and, in your own words, describe what it means.

Extra Credit

  1. Develop a general method named enlargeX that takes an additional integer parameter x and enlarges the width and height of the picture x times. For example the call p.enlarge(big, 3); should enlarge p 3 times placing the result in big.

© Ed Harcourt