-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCreateBackground.java
More file actions
52 lines (42 loc) · 1.42 KB
/
Copy pathCreateBackground.java
File metadata and controls
52 lines (42 loc) · 1.42 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.Graphics2D;
import javax.imageio.ImageIO;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;
public class CreateBackground
{
private static final int FINAL_SIZE_X = 700;
private static final int FINAL_SIZE_Y = 1000;
public static void main(String[] args){
createBackground();
}
public static BufferedImage loadImage(String file) {
BufferedImage sprite = null;
try {
sprite = ImageIO.read(new File(file + ".png"));
} catch (IOException e) {
e.printStackTrace();
}
return sprite;
}
public static void createBackground() {
BufferedImage tile = loadImage("grass");
final BufferedImage finalImage = new BufferedImage(FINAL_SIZE_Y, FINAL_SIZE_X,
BufferedImage.TYPE_INT_RGB);
Graphics2D g = finalImage.createGraphics();
int numX = FINAL_SIZE_X / tile.getWidth();
int numY = FINAL_SIZE_Y / tile.getHeight();
for (int x = 0; x < numX; x++){
for (int y = 0; y < numY; y++){
g.drawImage(tile, y*tile.getHeight(), x*tile.getWidth(), null);
}
}
g.dispose();
File background = new File("background.png");
try {
ImageIO.write(finalImage, "PNG", background);
} catch (IOException e){
e.printStackTrace();
}
}
}