-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathImage.java
More file actions
54 lines (52 loc) · 1.45 KB
/
Image.java
File metadata and controls
54 lines (52 loc) · 1.45 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
/**
* Final Game Image Class
* @Author Ilya Kononov
* @Date = January 22 2023
* This class loads image files and stores them inside
*/
import java.awt.Graphics;
import java.io.File;
import javax.imageio.ImageIO;
import java.awt.image.BufferedImage;
import java.io.IOException;
public class Image {
private BufferedImage picture;
private int width;
private int height;
private String picName;
public Image(String picName) {
// Load the image from file.
this.tryLoadImage(picName);
this.width = this.picture.getWidth();
this.height = this.picture.getHeight();
}
public void tryLoadImage(String picName) {
try {
this.picture = ImageIO.read(new File(picName));
this.picName = picName;
this.width = this.picture.getWidth();
this.height = this.picture.getHeight();
} catch (IOException ex) {
System.out.println("File not found! (" + picName + ")");
picture = null;
}
}
public int getWidth() {
return this.width;
}
public int getHeight() {
return this.height;
}
public String getPicName(){
return this.picName;
}
public BufferedImage getImage(){
return this.picture;
}
public void setImage(BufferedImage picture){
this.picture = picture;
}
public void draw(Graphics g, int x, int y) {
g.drawImage(this.picture, x, y, null);
}
}