Repository navigation
Expand file tree
/
Copy pathTextures.java
More file actions
52 lines (46 loc) · 1.41 KB
/
Copy pathTextures.java
File metadata and controls
52 lines (46 loc) · 1.41 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
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;
import javax.imageio.ImageIO;
import java.awt.Color;
import java.util.ArrayList;
import java.util.List;
public class Textures {
private List<Texture> textures;
public Textures(String folderName) {
textures = new ArrayList<>();
File folder = new File(folderName);
File[] listOfFiles = folder.listFiles();
if (listOfFiles != null) {
for (File file : listOfFiles) {
if (file.isFile() && file.getName().endsWith(".png")) {
textures.add(new Texture(loadTexture(file.getPath())));
}
}
}
}
public Color[][] loadTexture(String filePath) {
Color[][] pixels = new Color[32][32];
try {
BufferedImage image = ImageIO.read(new File(filePath));
for (int y = 0; y < 32; y++) {
for (int x = 0; x < 32; x++) {
pixels[y][x] = new Color(image.getRGB(x, y));
}
}
} catch (IOException e) {
e.printStackTrace();
}
return pixels;
}
public List<Texture> getTextures() {
return textures;
}
public Texture getTexture(int index) {
if (index >= 0 && index < textures.size()) {
return textures.get(index);
} else {
return null;
}
}
}