You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 

38 lines
1.3 KiB

package app.gameimage;
import javax.imageio.ImageIO;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;
public class GameImageUtils {
public static final String IMAGE_PATH_CLIENT = "images/games/";
public static final String EXTENSION = ".png";
static final String IMAGE_SOURCE_PATH_SERVER = "src/main/resources/META-INF/resources/images/chess-sources/";
static final String IMAGE_DEST_PATH_SERVER = "src/main/resources/META-INF/resources/images/games/";
private static final String EXTENSION_WITHOUT_DOT = "png";
private GameImageUtils() {}
public static BufferedImage readImage(String fileNameWithoutExtension) {
BufferedImage img = null;
try {
String path = IMAGE_SOURCE_PATH_SERVER + fileNameWithoutExtension + EXTENSION;
img = ImageIO.read(new File(path));
} catch (IOException e) {
e.printStackTrace();
}
return img;
}
public static void writeImage(BufferedImage img, String fileNameWithoutExtension) {
try {
String path = IMAGE_DEST_PATH_SERVER + fileNameWithoutExtension + EXTENSION;
File outputFile = new File(path);
ImageIO.write(img, EXTENSION_WITHOUT_DOT, outputFile);
} catch (IOException e) {
e.printStackTrace();
}
}
}