public class Demo {
public static void main(String[] args) {
try {
BufferedImage image = ImageIO.read(new File("G:\\1.png"));
int width = image.getWidth();
int height = image.getHeight();
image.flush();
System.out.println("Width : " + width);
System.out.println("Height : " + height);
Thumbnails.of("G:\\1.png").size(900,900).keepAspectRatio(false).toFile("G:\\2.png");
} catch (Exception e) {
e.printStackTrace();
}
}
}
<dependency>
<groupId>net.coobird</groupId>
<artifactId>thumbnailator</artifactId>
<version>0.4.8</version>
</dependency>