logo CodeStepByStep logo

mirror

Related Links:

Write a method named mirror that accepts a GImage parameter and modifies the image as shown below. The new image state should contain the original image, plus a horizontally reversed (mirrored) version of itself to its right, plus a vertically mirrored version of itself below, plus a horizontally-and-vertically mirrored version of itself below/right. Your method should modify the image to be twice as large and twice as wide as the original. The screenshots below show the state of an image before and after a call to your method:

Before: After:
before after

Your code should work for an image of any size of at least 1x1 pixels. The width and height might not be equal.

Constraints: You may use one auxiliary data structure of your choice to help you solve this problem. (Asking for the pixel array of an existing image does not count as an auxiliary data structure; when your code says 'new', that is what counts.)

Type your Java solution code here:


This is a method exercise. Write a Java method as described. Do not write a complete program or class; just the method(s) above.

You must log in before you can solve this problem.

Log In

Need help?

If you do not understand how to solve an exercise or why your solution doesn't work, please contact your TA or instructor.
If something seems wrong with the site (errors, slow performance, incorrect tests, etc.), please

Is there a problem? Contact a site administrator.

©, all rights reserved.