logo CodeStepByStep logo

tile

Related Links:

Write a method named tile that accepts a GImage parameter and modifies the image as shown below. Your method should create repeated copies of an image. The method accepts three parameters: a GImage, and a width and height as integers. Your code should modify the image so that its pixels are looped and repeated ("tiled") over an area with the given width and height. The screenshots below show the state of an image before and after a call to your method.

GImage myImage = new GImage("smiley.png");
tile(myImage, 350, 230);
Before After
before after

Your code should work for an image of any size of at least 1x1 pixels. The image's width and height might not be equal. Note that the destination width and height integers passed might be larger or smaller than the image's original size.

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.