-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMirroredImage.java
More file actions
32 lines (27 loc) · 1.01 KB
/
MirroredImage.java
File metadata and controls
32 lines (27 loc) · 1.01 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
import org.code.theater.*;
import org.code.media.*;
import java.io.FileNotFoundException;
// TO DO: Make MirroredImage a subclass of Image.
public class MirroredImage extends Image{
private Pixel [][] imagePixels;
// TO DO: Declare a 2D Pixel array called imagePixels.
// TO DO: Complete the constructor by calling super() and initializing
// imagePixels to the 2D Pixel array returned from ImageEditor.getPixels().
public MirroredImage(String filename) throws FileNotFoundException {
super(filename);
imagePixels = ImageEffect.getPixels(this);
}
// TO DO: Write your code to vertically mirror the image.
public void verticalMirror() {
Pixel leftPixel = null;
Pixel rightPixel = null;
int width = imagePixels[0].length;
for(int col = 0; col < width/2; col++){
for(int row = 0; row < imagePixels.length; row++){
leftPixel = imagePixels[row][col];
rightPixel = imagePixels[row][width - 1 - col];
rightPixel.setColor(leftPixel.getColor());
}
}
}
}