java获取上传图片宽度高度

 
  1. import java.awt.image.BufferedImage;   
  2. import java.io.File;   
  3. import java.io.IOException;   
  4. import javax.imageio.ImageIO;   
  5.   
  6. public class Test {   
  7.   
  8.     public static void main(String[] args) {   
  9.         File picFile = new File("D:\\1.gif"); // 图片文件路径   
  10.         BufferedImage image = null;   
  11.         try {   
  12.             image = ImageIO.read(picFile);   
  13.         } catch (IOException e) {   
  14.             e.printStackTrace();   
  15.         }   
  16.         int width = image.getWidth();// 图片宽度   
  17.         int height = image.getHeight();// 图片高度   
  18.         System.out.println("width=" + width);   
  19.         System.out.println("height=" + height);   
  20.     }   
  21.   
  22. }  

你可能感兴趣的:(java,String,image,null)