CS 107: Pictures and Sounds: Programming with Multimedia

Kalamazoo College

Winter 2009

Mini-Lab: Using the CopyInto and CropPicture Functions

 


The objective of this mini-lab is to experiment with the copyInto and cropPicture functions that we have provided.



Experimenting with Crop

Cropping an image means to cut out a certain part of the image and discard the rest of it. Actually, rather than change the original picture, copyPicture will create a new picture that consists only of the desired section , leaving the original picture unchanged. Cropping is one of the essential functions in image processing/manipulation. Understanding picture dimensions (height and width) is an important part of cropping an image.

Exercises:

These exercises should all be done in the Command area of JES. You should write your answers to the questions in the exercises on a piece of paper.

  1. Select a picture to use. You may name it whatever you like, but it will be referred to as myPict in these exercises.

  2. Type in and enter the line
    littlePic = cropPicture(myPict, 1, 1, 50, 50)

    What does littlePic look like? Which part of myPict is it?

  3. Now try the line:
    littleBiggerPic = cropPicture(myPict, 1, 1, getWidth(myPict)/2, getHeight(myPict)/2)

    What does this do? Which part of myPict is it?

  4. How would you crop the bottom-right quadrant of your picture? Write down your line of code.

  5. Open myPict in MediaTools -> Picture Tool. Find a section to crop by moving the mouse around over the picture. The x- and y- coordinates are displayed at the top. Write down the statement you would use to crop this section and save it in a variable.

 


Combining Crop and CopyInto

Exercises

These exercises should all be done in the Command area in JES. Continue writing your answers on the same piece of paper.

  1. Select another picture to use as a canvas. You may name it whatever you like, but it will be referred to as canvas in these exercises.

  2. Use the built-in copyInto function to put littlePic from the previous exercises in the upper-left corner of canvas. Does this modify canvas?

  3. Try copying littleBiggerPic somewhere into the middle of canvas.

  4. (If time permits) Try copying littlePic into littleBiggerPic, and then littleBiggerPic somewhere into an empty canvas. What does your code look like? Write it down.