minesweeper/src/dev/kske/minesweeper/TextureLoader.java

38 lines
1.0 KiB
Java
Raw Permalink Normal View History

package dev.kske.minesweeper;
import java.awt.Image;
import java.awt.image.BufferedImage;
import java.io.IOException;
import javax.imageio.ImageIO;
/**
* Project: <strong>Minesweeper</strong><br>
* File: <strong>TextureLoader.java</strong><br>
* Created: <strong>25.03.2019</strong><br>
* Author: <strong>Kai S. K. Engelbart</strong>
*/
public class TextureLoader {
private TextureLoader() {}
/**
* Loads an image from the resource folder and scales it to a square.
*
* @param name The name of the file without the PNG extension in the resource
* folder
* @param scale The side length of the square to which the image will be scaled
* @return The scaled image
*/
public static Image loadScaledImage(String name, int scale) {
BufferedImage in = null;
try {
2019-07-16 18:47:26 +02:00
in = ImageIO.read(TextureLoader.class.getResourceAsStream("/" + name + ".png"));
} catch (IOException e) {
e.printStackTrace();
}
Image scaled = in.getScaledInstance(scale, scale, Image.SCALE_SMOOTH);
return scaled;
}
}