import java.awt.Graphics2D;
import java.awt.RenderingHints;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;
import javax.imageio.ImageIO;
public class PuzzlePic {
private static BufferedImage puzzlePic;
static {
try {
puzzlePic = ImageIO.read(PuzzlePic.class.getResourceAsStream("puzzle.jpg"));
}
catch(IOException e) {
e.printStackTrace();
}
}
public static BufferedImage getPuzzlePicture() {
return puzzlePic;
}
public static void setPuzzlePicture(File file) {
try {
puzzlePic = resize(ImageIO.read(file), 512, 512);
}
catch(IOException e) {
try {
puzzlePic = ImageIO.read(PuzzlePic.class.getResourceAsStream("puzzle.jpg"));
}
catch(IOException f) {
f.printStackTrace();
}
}
}
private static BufferedImage resize(BufferedImage img, int newW, int newH) {
int w = img.getWidth();
int h = img.getHeight();
BufferedImage dimg = new BufferedImage(newW, newH, img.getType());
Graphics2D g = dimg.createGraphics();
g.setRenderingHint(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BILINEAR);
g.drawImage(img, 0, 0, newW, newH, 0, 0, w, h, null);
g.dispose();
return dimg;
}
}