[Java]获取图片高和宽

时间:2021-06-11 06:03:13

  通过javax.imageio.ImageIO类中的read()函数读取的图片,存放在类java.awt.image.BufferedImage类中。调用BufferedImage类中的getWidth()和getHeight()获取图片的宽度大小和高度大小。

 import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;
import javax.imageio.ImageIO;
import com.Sunday.TankWar.configure.TankWarConfigure; public class ImageInformation { public static void main(String[] args) throws IOException {
String imageName = "home.jpg";
BufferedImage image = ImageIO.read(new File(TankWarConfigure.imagePath + imageName)); System.out.println("Width: " + image.getWidth());
System.out.println("Height: " + image.getHeight()); } }