He元素

Don't be shy just try!

  博客园 :: 首页 :: 博问 :: 闪存 :: 新随笔 :: 联系 :: 订阅 订阅 :: 管理 ::

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);    

 

posted on 2017-01-05 17:18  He元素  阅读(313)  评论(0编辑  收藏  举报