//通過(guò)地址獲取bitmap public Bitmap getBitmap(String path) { Bitmap bitmap = null; try { //封裝url URL url = new URL(path); //獲得httpurl連接對(duì)象 HttpURLConnection connection = (HttpURLConnection) url.openConnection(); //設(shè)置連接超時(shí) connection.setConnectTimeout(5*1000); //設(shè)置請(qǐng)求方法 connection.setRequestMethod("GET"); //判斷請(qǐng)求狀態(tài)碼是否連接成功 if (connection.getResponseCode() == 200) { InputStream is = connection.getInputStream(); //bitmapfactory可以有多種生存bitmap的方法 bitmap = BitmapFactory.decodeStream(is); } } catch (Exception e) { e.printStackTrace(); } return bitmap; } //獲得字節(jié)數(shù)組 public void getBytesByIs(InputStream is) throws IOException { ByteArrayOutputStream bos = new ByteArrayOutputStream(); int len ; byte[] data = new byte[1024]; while((len = is.read(data))!=-1){ bos.write(data, 0, len); } byte[] bytes = bos.toByteArray(); }
名稱欄目:android開(kāi)發(fā)——獲取網(wǎng)絡(luò)圖片
文章位置:http://muchs.cn/article0/ipiiio.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供微信小程序、靜態(tài)網(wǎng)站、網(wǎng)站策劃、網(wǎng)站排名、定制網(wǎng)站、服務(wù)器托管
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請(qǐng)盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如需處理請(qǐng)聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來(lái)源: 創(chuàng)新互聯(lián)