public class ImageUtilities {
public static BufferedImage loadBitmap(String fileName) throws IOException {
BufferedImage image = null;
try {
image = ImageIO.read(ImageUtilities.class.getResource(fileName));
} catch (IOException e) {
throw (e);
}
return image;
}
public static BufferedImage loadTextAsImage(String text) throws IOException {
int charWidth = 20, charHeight = 20;
BufferedImage font = null;
try {
font = loadBitmap("/images/text_1.png");
} catch (IOException e) {
throw (e);
}
BufferedImage textImage = new BufferedImage(text.length() * charWidth, charHeight, BufferedImage.TRANSLUCENT);
Graphics g = textImage.getGraphics();
for(int i = 0; i < text.length();i++){
BufferedImage letter = font.getSubimage(getLocation(text.charAt(i)).x, getLocation(text.charAt(i)).y, charWidth, charHeight);
g.drawImage(letter, i * charWidth, 0, null);
}
return textImage;
}
private static Point getLocation(char c) {
switch (c) {
case 'a':
return new Point(0, 20);
case 'b':
return new Point(20, 20);
case 'c':
return new Point(40, 20);
case 'd':
return new Point(60, 20);
case 'e':
return new Point(80, 20);
case 'f':
return new Point(100, 20);
case 'g':
return new Point(120, 20);
case 'h':
return new Point(140, 20);
case 'i':
return new Point(160, 20);
case 'j':
return new Point(180, 20);
case 'k':
return new Point(200, 20);
case 'l':
return new Point(220, 20);
case 'm':
return new Point(240, 20);
case 'n':
return new Point(260, 20);
case 'o':
return new Point(280, 20);
case 'p':
return new Point(300, 20);
case 'q':
return new Point(320, 20);
case 'r':
return new Point(340, 20);
case 's':
return new Point(360, 20);
case 't':
return new Point(380, 20);
case 'u':
return new Point(400, 20);
case 'v':
return new Point(420, 20);
case 'w':
return new Point(440, 20);
case 'x':
return new Point(460, 20);
case 'y':
return new Point(480, 20);
case 'z':
return new Point(500, 20);
case 'A':
return new Point(0, 0);
case 'B':
return new Point(20, 0);
case 'C':
return new Point(40, 0);
case 'D':
return new Point(60, 0);
case 'E':
return new Point(80, 0);
case 'F':
return new Point(100, 0);
case 'G':
return new Point(120, 0);
case 'H':
return new Point(140, 0);
case 'I':
return new Point(160, 0);
case 'J':
return new Point(180, 0);
case 'K':
return new Point(200, 0);
case 'L':
return new Point(220, 0);
case 'M':
return new Point(240, 0);
case 'N':
return new Point(260, 0);
case 'O':
return new Point(280, 0);
case 'P':
return new Point(300, 0);
case 'Q':
return new Point(320, 0);
case 'R':
return new Point(340, 0);
case 'S':
return new Point(360, 0);
case 'T':
return new Point(380, 0);
case 'U':
return new Point(400, 0);
case 'V':
return new Point(420, 0);
case 'W':
return new Point(440, 0);
case 'X':
return new Point(460, 0);
case 'Y':
return new Point(480, 0);
case 'Z':
return new Point(500, 0);
case '1':
return new Point(0, 40);
case '2':
return new Point(20, 40);
case '3':
return new Point(40, 40);
case '4':
return new Point(60, 40);
case '5':
return new Point(80, 40);
case '6':
return new Point(100, 40);
case '7':
return new Point(120, 40);
case '8':
return new Point(140, 40);
case '9':
return new Point(160, 40);
case '0':
return new Point(180, 40);
case '!':
return new Point(200, 40);
case '*':
return new Point(220, 40);
case '(':
return new Point(240, 40);
case ')':
return new Point(260, 40);
case '?':
return new Point(280, 40);
case '.':
return new Point(300, 40);
case ',':
return new Point(320, 40);
case '@':
return new Point(340, 40);
case '#':
return new Point(360, 40);
default:
return new Point(500, 40);
}
}
}