android中的BitMap(二)从网络和资源文件中获得一个BitMap

//取得网络上图片资源的路径

String urlstring="http://img.wallba.com/Public/Upload/Image/qichebizi/

asidunmading7/134/20113151413962.jpg";
  try {

//建立网络连接
   URL imageURl=new URL(urlstring);
   URLConnection con=imageURl.openConnection();
   con.connect();
   InputStream in=con.getInputStream();
   Bitmap bitmap=BitmapFactory.decodeStream(in);
   
   //方法二,从资源文件中获得一个图片转换成BitMap
   BitmapDrawable draw=(BitmapDrawable) getResources().getDrawable(R.drawable.ss);
   Bitmap m=draw.getBitmap();
   ImageView imageView=(ImageView) findViewById(R.id.image);

//在组件上显示当前从网络上获取的图片
   imageView.setImageBitmap(bitmap);
  } catch (Exception e) {
   // TODO Auto-generated catch block
   e.printStackTrace();
  }

 

 

//记得要加上网络权限

 

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

路漫漫其修远兮 吾将上下而求索
原文地址:https://www.cnblogs.com/hudabing/p/3075539.html