java获取图片原始尺寸

你说的曾经没有我的故事 提交于 2019-12-28 17:06:10

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

 

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!