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, cropPicture 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.


All of these exercises except for the first one should be done in the Command area of JES. You should type up your answers to the questions.

  1. Copy the cropPicture and copyInto functions from the support code functions that we have provided and paste them into the program area in JES. You should also copy and include the comments before the functions. (NOTE: There is a built-in (JES) version of copyInto that modifies the canvas and does not do any error-checking on the dimensions of the pictures and the position (upper-left corner) of the picture to be copied. Therefore, we WILL NOT be using the built-in version.)

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

  3. Type in and enter the line
    littlePic = cropPicture(myPict, 0, 0, 50, 50)

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

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

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

  5. How would you crop the bottom-right quadrant of your picture? Write down your line of code. Test that your line of code works.

  6. 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. Test that your statement works.


Combining Crop and CopyInto


These exercises should all be done in the Command area in JES. Continue typing up your answers.

  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 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.