Write a general crop function that takes a source picture, the start X value, the start Y value, the end X value, and the end Y value. Create and return the new picture and copy just the specified area into the new picture.

What will be an ideal response?

```
def crop (src, x1, y1, x2, y2):
w = getWidth(src)
h = getHeight(src)
canvas = makeEmptyPicture(x2-x1,y2-y1)
for x in range(x1, x2):
for y in range(y1,y2):
p = getPixel(canvas, x-x1, y-y1)
p2 = getPixel(src, x, y)
color = getColor(p2)
setColor(p, color)
return canvas
```

Note: The important lines here are to make sure that you grab from the correct pixels from the canvas. Grabbing the pixels “x” and “y” will not work, as they may be larger than the canvas you’re copying to.

Computer Science & Information Technology

You might also like to view...

Which of the following is part of the vector component of a distance vector metric in routing?

A) The link B) The next hop router C) The distance D) The destination subnet

Computer Science & Information Technology

How should the event-handler method for the control OutputLabel and the event Click be named?

a) OutputLabel_Click b) Click c) OutputLabel.Click d) None of the above.

Computer Science & Information Technology