Data hosted with ♥ by Pastebin.com - Download Raw - See Original
  1. import java.awt.Graphics2D;
  2. import java.awt.RenderingHints;
  3. import java.awt.image.BufferedImage;
  4. import java.io.File;
  5. import java.io.IOException;
  6.  
  7. import javax.imageio.ImageIO;
  8.  
  9.  
  10. public class PuzzlePic {
  11. private static BufferedImage puzzlePic;
  12.  
  13. static {
  14. try {
  15. puzzlePic = ImageIO.read(PuzzlePic.class.getResourceAsStream("puzzle.jpg"));
  16. }
  17. catch(IOException e) {
  18. e.printStackTrace();
  19. }
  20. }
  21.  
  22. public static BufferedImage getPuzzlePicture() {
  23. return puzzlePic;
  24. }
  25. public static void setPuzzlePicture(File file) {
  26. try {
  27. puzzlePic = resize(ImageIO.read(file), 512, 512);
  28. }
  29. catch(IOException e) {
  30. try {
  31. puzzlePic = ImageIO.read(PuzzlePic.class.getResourceAsStream("puzzle.jpg"));
  32. }
  33. catch(IOException f) {
  34. f.printStackTrace();
  35. }
  36. }
  37. }
  38. private static BufferedImage resize(BufferedImage img, int newW, int newH) {
  39. int w = img.getWidth();
  40. int h = img.getHeight();
  41. BufferedImage dimg = new BufferedImage(newW, newH, img.getType());
  42. Graphics2D g = dimg.createGraphics();
  43. g.setRenderingHint(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BILINEAR);
  44. g.drawImage(img, 0, 0, newW, newH, 0, 0, w, h, null);
  45. g.dispose();
  46. return dimg;
  47. }
  48. }