-
Notifications
You must be signed in to change notification settings - Fork 0
/
image-version.java
42 lines (33 loc) · 1.14 KB
/
image-version.java
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
33
34
35
36
37
38
39
40
41
42
/**
* Write a description of ImageInversion here.
*
* @Damilare Oyediran
* @version (a version number or a date)
*/
import edu.duke.*;
import java.io.*;
import org.apache.commons.csv.*;
public class ImageInversion {
//
public ImageResource makeInversion(ImageResource inImage) {
ImageResource outImage = new ImageResource(inImage.getWidth(), inImage.getHeight());
for(Pixel pixel : outImage.pixels()){
Pixel inPixel = inImage.getPixel(pixel.getX(), pixel.getY());
int newRed = 255 - inPixel.getRed();
int newBlue = 255 - inPixel.getBlue();
int newGreen = 255 - inPixel.getGreen();
pixel.setRed(newRed);
pixel.setGreen(newGreen);
pixel.setBlue(newBlue);
}
return outImage;
}
public void testImageInversion(){
ImageResource ir = new ImageResource();
ImageResource inverImage = makeInversion(ir);
String fileName = inverImage.getFileName();
String newName = "inverted-" + fileName;
inverImage.setFileName(newName);
inverImage.draw();
}
}