-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathImageIOUtil.java
More file actions
80 lines (47 loc) · 1.47 KB
/
ImageIOUtil.java
File metadata and controls
80 lines (47 loc) · 1.47 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
package utils;
import java.awt.Image;
import java.awt.Toolkit;
//import java.awt.Toolkit;
import java.io.File;
import java.awt.image.BufferedImage;
import javax.imageio.ImageIO;
import javax.swing.ImageIcon;
public class ImageIOUtil {
private static ImageIOUtil imageIOUtilInstance = null;
private static ImageIcon imagenIcon;
private static BufferedImage bufferedImage;
public ImageIOUtil() {}
public static ImageIOUtil getInstance() {
if(imageIOUtilInstance == null) {
imageIOUtilInstance = new ImageIOUtil();
}
return imageIOUtilInstance;
}
public static ImageIcon readImageIcon(String path) {
try {
imagenIcon = new ImageIcon(path);
}catch(Exception e){e.printStackTrace();}
return imagenIcon;
}
public static Image readImage(String path) {
return readImageIcon(path).getImage();
}
public static Image readBufferedImage(String path) {
try {
bufferedImage = ImageIO.read(new File(path));
}catch(Exception e) {e.printStackTrace();}
return bufferedImage;
}
public ImageIcon getIcon(String path) {
return new ImageIcon(this.getClass().getResource(path));
}
public Image getIconImage(String path) {
return this.getIcon(path).getImage();
}
public Image getResource(String path) {
return new ImageIcon(this.getClass().getResource(path)).getImage();
}
public Image readImageToolkit(String path) {
return Toolkit.getDefaultToolkit().getImage(ClassLoader.getSystemResource(path));
}
}