[Java]获取图片高和宽

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

 1 import java.awt.image.BufferedImage;
 2 import java.io.File;
 3 import java.io.IOException;
 4 import javax.imageio.ImageIO;
 5 import com.Sunday.TankWar.configure.TankWarConfigure;
 6 
 7 public class ImageInformation {
 8 
 9     public static void main(String[] args) throws IOException {
10         String imageName = "home.jpg";
11         BufferedImage image = ImageIO.read(new File(TankWarConfigure.imagePath + imageName));
12     
13         System.out.println("Width: " + image.getWidth());
14         System.out.println("Height: " + image.getHeight());
15         
16     } 
17 
18 }

 

你可能感兴趣的:(java)