posts - 35, comments - 0, trackbacks - 0, articles - 0
            BlogJava :: 首頁 :: 新隨筆 :: 聯系 :: 聚合  :: 管理

          通過url獲取圖片的寬高

          Posted on 2012-09-26 09:34 timelyxyz 閱讀(417) 評論(0)  編輯  收藏
           1     private static Map<String, Long> getPictureHeightAndWidthMap(String picUrl) {
           2         Map<String, Long> map = new HashMap();
           3         try {
           4             URL url = new URL(picUrl);
           5             HttpURLConnection connection = (HttpURLConnection) url
           6                     .openConnection();
           7             DataInputStream in = new DataInputStream(
           8                     connection.getInputStream());
           9             BufferedImage image = ImageIO.read(in);
          10             map.put("w", image.getWidth() * 1L);
          11             map.put("h", image.getHeight() * 1L);
          12             connection.disconnect();
          13             in.close();
          14         } catch (IOException e) {
          15             e.printStackTrace();
          16         }
          17         return map;
          18     }
          19 
          20     public static Long getHeight(String picUrl) {
          21         Map<String, Long> map = getPictureHeightAndWidthMap(picUrl);
          22         return null == map.get("h") ? 0 : map.get("h");
          23     }
          24 
          25     public static Long getWidth(String picUrl) {
          26         Map<String, Long> map = getPictureHeightAndWidthMap(picUrl);
          27         return null == map.get("w") ? 0 : map.get("w");
          28     }

          只有注冊用戶登錄后才能發表評論。


          網站導航:
           
          主站蜘蛛池模板: 清流县| 陈巴尔虎旗| 宁德市| 乌兰浩特市| 伊通| 华蓥市| 师宗县| 曲沃县| 上林县| 卢湾区| 遂川县| 青铜峡市| 睢宁县| 南郑县| 英德市| 汝州市| 赣州市| 尚义县| 宣武区| 富裕县| 乌恰县| 射洪县| 商洛市| 青川县| 全椒县| 成武县| 兴安盟| 云安县| 十堰市| 宁河县| 临澧县| 蚌埠市| 望奎县| 民和| 石门县| 页游| 金乡县| 湘西| 武宁县| 资溪县| 永丰县|