Cropping is the process of reducing the size of an image by removing particular portions of its outer regions. In DarkRoom, a user can crop an image by dragging a rectangular box around the part of the image they wish to preserve and clicking the “Crop” button.
Your job is to implement the following method:
public GImage crop(GImage source, int cropX, int cropY, int cropWidth, int cropHeight);
which takes in as a parameter a GImage as well as 4 parameters that specify the cropped region. Specifically, the first pair of these parameters (namely cropX and cropY) are the coordinates of the top left corner of the cropped region in the original image, and the latter pair are the width and height of the region. For example, if you had a GImage named picture whose pixel array looked like this:
and you were to call crop(picture, 2, 3, 3, 2), your method would return a GImage with the following pixel array:
Note that the pixel in the top left corner of the cropped region (with the value 18) has an x- coordinate of 2 and a y-coordinate of 3 in the original image, and that the cropped region itself has a width of 3 pixels and a height of 2 pixels. You can safely assume that the cropped region fits entirely within the original image.