java获取图片原始尺寸

URL url = null;  
InputStream is = null;  
BufferedImage img = null;

try {  
 url = new URL(picurl);  
 is = url.openStream();  
 img = ImageIO.read(is);  
} catch (MalformedURLException e) {  
 e.printStackTrace();  
} catch (IOException e) {  
 e.printStackTrace();  
} finally {  
   
 try {  
     is.close();  
 } catch (IOException e) {  
     e.printStackTrace();  
 }  
}  


//System.out.println(img.getHeight()+"/"+img.getWidth());

String str = "{\"width\":\""+img.getWidth()+"\",\"height\":\""+img.getHeight()+"\"}";
out.print(str);    

 

相关文章: