+网络图片浏览

mac2022-06-30  19

1、权限

<uses-permission android:name="android.permission.INTERNET"/>

2、代码

//这次的HttpURLConnection仅针对Http连接,效率胜于URLConnection。 String uriPic =et.getText().toString(); URL imageUrl = null; Bitmap bitmap = null; try{ imageUrl = new URL(uriPic);// new URL对象将网址传入 } catch (MalformedURLException e){ e.printStackTrace(); } try{ HttpURLConnection conn = (HttpURLConnection) imageUrl.openConnection();// 取得连接 conn.connect(); InputStream is = conn.getInputStream();//取得返回的InputStream bitmap = BitmapFactory.decodeStream(is);//将InputStream变成Bitmap is.close();//关闭InputStream }catch (IOException e){ e.printStackTrace(); } iv.setImageBitmap(bitmap);

 

转载于:https://www.cnblogs.com/wdc224/p/3676705.html

相关资源:JAVA上百实例源码以及开源项目
最新回复(0)