Repository navigation
Expand file tree
/
Copy pathMain.java
More file actions
95 lines (78 loc) · 2.84 KB
/
Copy pathMain.java
File metadata and controls
95 lines (78 loc) · 2.84 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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Scanner;
import javax.imageio.ImageIO;
public class Main {
public static void main(String[] args) throws FileNotFoundException {
File file = new File("Diamond colors.txt");
Scanner fileReader = new Scanner(file);
ArrayList <diamond> colors = new ArrayList<diamond>();
/*
while (fileReader.hasNextLine()){
String line = fileReader.nextLine();
String[] splitstring = line.split("\t");
colors.add(new diamond(Integer.parseInt(splitstring[0]), splitstring[1], splitstring[2]));
}
fileReader.close();
*/
File image = new File("C:\\Users\\felzh\\Pictures\\messing around with dimond art\\2021 Yearbook photo-David - Copy.jpg");
File imageUpdate = new File("C:\\\\Users\\\\felzh\\\\Pictures\\\\messing around with dimond art\\\\2021 Yearbook photo-David - Copy2.jpg");
BufferedImage img = null;
BufferedImage img2 = null;
try {
img = ImageIO.read(image);
img2 = ImageIO.read(imageUpdate);
} catch (IOException e) {
e.printStackTrace();
}
System.out.print("Images loaded");
int white = (255 << 24) | (255 << 16) | (255 << 8) | 255;
for (int i=0; i<img2.getWidth()-1;i++) {
for (int j=0; j<img2.getHeight()-1;j++) {
img2.setRGB(i, j, white);
}
}
try {
ImageIO.write(img2, "jpg", imageUpdate);
} catch (IOException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
System.out.print("Whited");
int column=0,row=0;
for (int i = 0; i<img.getWidth()-1;i+=2) {
for(int j = 0; j<img.getHeight()-1; j+=2) {
int h = 0, h2 = 0, h3 = 0, h4 = 0, red = 0, green = 0, blue = 0;
//System.out.printf("%d %d\n", i, j);
try {
h = img.getRGB(i, j); //& 0x00FFFFFF; ____________
h2 = img.getRGB(i+1, j); //& 0x00FFFFFF; |___|___|___|
h3 =img.getRGB(i, j+1); //& 0x00FFFFFF; |___|_X_|_X_|
h4 = img.getRGB(i+1, j+1); //& 0x00FFFFFF; |___|_X_|_X_|
red = (((h>>16)&0xFF)+((h2>>16)&0xFF)+((h3>>16)&0xFF)+((h4>>16)&0xFF))/4;
green = (((h>>8)&0xFF)+((h2>>8)&0xFF)+((h3>>8)&0xFF)+((h4>>8)&0xFF))/4;
blue = ((h&0xFF)+(h2&0xFF)+(h3&0xFF)+(h4&0xFF))/4;
System.out.print("averaged");
int combined = (red << 16) | (green << 8) | (blue);
System.out.printf("Coordinates: %d%-5d", column, row);
img2.setRGB(column,row,combined);
} catch (Exception e) {
e.printStackTrace();
}
//System.out.printf("Color: R:%d G:%d B:%d\n", red, green, blue);
row++;
}
column++;
row=0;
}
try {
ImageIO.write(img2, "jpg", imageUpdate);
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}