-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCoordsToJpg.java
168 lines (159 loc) · 3.8 KB
/
CoordsToJpg.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
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
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
import java.awt.*;
import java.awt.geom.AffineTransform;
import javax.swing.*;
import java.io.File;
import java.io.IOException;
import java.awt.image.BufferedImage;
import javax.imageio.ImageIO;
import java.io.BufferedReader;
import java.io.FileReader;
public class CoordsToJpg{
public static Color getColor(String col) {
Color color = Color.WHITE;
switch (col.toLowerCase()) {
case "vlred":
color = new Color(255,102,102);
break;
case "lred":
color = new Color(255,51,51);
break;
case "red":
color = new Color(255,0,0);
break;
case "dred":
color = new Color(204,0,0);
break;
case "vlblue":
color = new Color(51,204,255);
break;
case "lblue":
color = new Color(51,153,255);
break;
case "blue":
color = new Color(0,0,255);
break;
case "dblue":
color = new Color(0,0,204);
break;
case "vlgreen":
color = new Color(102,255,102);
break;
case "lgreen":
color = new Color(0,255,51);
break;
case "green":
color = new Color(0,255,0);
break;
case "dgreen":
color = new Color(0,153,0);
break;
case "lyellow":
color = new Color(255, 255, 153);
break;
case "yellow":
color = new Color(255, 255, 0);
break;
case "dyellow":
color = new Color(255, 204, 0);
break;
case "lorange":
color = new Color(255, 153, 0);
break;
case "orange":
color = new Color(255, 102, 0);
break;
case "gold":
color = new Color(255, 204, 51);
break;
case "lgrey":
color = new Color(204, 204, 204);
break;
case "dgrey":
color = new Color(153, 153, 153);
break;
case "vdgrey":
color = new Color(51, 51, 51);
break;
case "lbrown":
color = new Color(153, 102, 0);
break;
case "dbrown":
color = new Color(102, 0, 0);
break;
case "black":
color = new Color(0, 0, 0);
break;
case "purple":
color = new Color(102, 0, 153);
break;
case "maroon":
color = new Color(153, 0, 0);
break;
case "salmon":
color = new Color(255, 102, 102);
break;
case "magneta":
color = Color.MAGENTA;
break;
case "magneta4":
color = Color.MAGENTA.darker();
break;
default:
System.out.println("Color " + col.toLowerCase() + " not found!");
}
return color;
}
public static void saveImage() throws IOException {
BufferedImage bufferedImage = new BufferedImage(300,300, BufferedImage.TYPE_INT_RGB);
Graphics2D g2d = bufferedImage.createGraphics();
int [] polygonXs = new int[7];
int [] polygonYs = new int[7];
Shape shape;
File img_file;
BufferedReader br = new BufferedReader(new FileReader("Coords/head_modified_xyc.txt"));
String line;
String img_name = "";
String color = "";
String [] xy = new String[2];
while ((line = br.readLine()) != null) {
if (line.charAt(0) == '>') {
// for every new figure:
g2d.setColor(Color.WHITE);
g2d.fillRect(0, 0, 300, 300);
img_name = line.substring(1);
}
// until we reach new figure
while (color != null) {
br.mark(1000);
color = br.readLine();
if (color == null)
break;
if (color.charAt(0) == '>') {
br.reset();
break;
}
g2d.setColor(getColor(color));
// Define an arrow shape using a polygon
for (int i = 0; i < 7; i++) {
xy = (br.readLine()).split("\t",2);
polygonXs[i] = (int)Float.parseFloat(xy[0]);
polygonYs[i] = (int)Float.parseFloat(xy[1]);
}
shape = new Polygon(polygonXs, polygonYs, polygonXs.length);
g2d.fill(shape);
}
// when we reach new figure:
img_file = new File("modified_images/"+ img_name + ".jpg");
g2d.drawImage(bufferedImage, 0,0,null);
ImageIO.write(bufferedImage, "jpg", img_file);
}
}
public static void main(String[] args) {
try {
saveImage();
}
catch (IOException ex) {
System.out.println("IO Exception Caught!");
}
}
}