-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGetColor.java
More file actions
107 lines (102 loc) · 2.25 KB
/
GetColor.java
File metadata and controls
107 lines (102 loc) · 2.25 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
96
97
98
99
100
101
102
103
104
105
106
107
import java.awt.Color;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import javax.imageio.ImageIO;
public class GetColor {
int rgb, r, g, b;
int colorNum = 0;
ArrayList<Integer> cList = new ArrayList<>();
public GetColor(String num) {
BufferedImage image = null;
try {
image = ImageIO.read(new File("image/NazoMain/" + num + ".png"));
} catch (IOException e) {
System.out.println("ファイル読み込みエラー");
}
// 色抽出
int tate = 5;
for (int i1 = 1; i1 < (GlobalVal.height * 2); i1 += 2) {
for (int i2 = 1; i2 < (GlobalVal.width * 2); i2 += 2) {
// 縦範囲取得
for (int i3 = -tate; i3 < tate; i3++)
rgb += image.getRGB(image.getWidth() * i2 / (GlobalVal.width * 2),
image.getHeight() * i1 / (GlobalVal.height * 2) + i3);
rgb /= (tate * 2);
Color color = new Color(rgb);
r = color.getRed();
g = color.getGreen();
b = color.getBlue();
separate((i1 - 1) / 2, (i2 - 1) / 2, false);
// check();
rgb = 0;
}
}
}
public void separate(int y, int x, boolean print) {
if (!cList.contains(g) && g < 254) {
switch (colorNum) {
case 0:
cList.add(g);
GlobalVal.p[y][x] = 1;
colorNum++;
if (print)
System.out.print("1");
break;
case 1:
cList.add(g);
GlobalVal.p[y][x] = 2;
colorNum++;
if (print)
System.out.print("2");
break;
case 2:
cList.add(g);
GlobalVal.p[y][x] = 3;
colorNum++;
if (print)
System.out.print("3");
break;
case 3:
cList.add(g);
GlobalVal.p[y][x] = 4;
colorNum++;
if (print)
System.out.print("4");
break;
default:
break;
}
} else {
switch (cList.indexOf(g)) {
case 0:
GlobalVal.p[y][x] = 1;
if (print)
System.out.print("1");
break;
case 1:
GlobalVal.p[y][x] = 2;
if (print)
System.out.print("2");
break;
case 2:
GlobalVal.p[y][x] = 3;
if (print)
System.out.print("3");
break;
case 3:
GlobalVal.p[y][x] = 4;
if (print)
System.out.print("4");
break;
default:
break;
}
}
}
public void check() {
System.out.print(g + " ");
// System.out.print("(" + r + "," + g + "," + b + ")");
}
}