Android显示网络图片Step1:
//浏览网络图片
public class WebImageViewActivity extends Activity implements OnItemClickListener
{
 //String imageUrl = "http://i.pbase.com/o6/92/229792/1/80199697.uAs58yHk.50pxCross_of_the_Knights_Templar_svg.png"; 
 public static String imageUrl = "";
   Bitmap bmImg; 
   ImageView imView;
  
 @Override
 public void onCreate(Bundle savedInstanceState)
 {
  super.onCreate(savedInstanceState);
  setContentView(R.layout.web_imageview_activity);
  
  //imageUrl="http://www.iwapzone.com/templets/default/images/apc_bg.png";
  imView = (ImageView) findViewById(R.id.imgview); 

  imView.setImageBitmap(returnBitMap(imageUrl)); 
 }

 public Bitmap returnBitMap(String url) {

  URL myFileUrl = null;
  Bitmap bitmap = null;

  try {
   myFileUrl = new URL(url);

  } catch (MalformedURLException e) {
   e.printStackTrace();
  }

  try {
   HttpURLConnection conn = (HttpURLConnection) myFileUrl
   .openConnection();
   conn.setDoInput(true);
   conn.connect();

   InputStream is = conn.getInputStream();
   bitmap = BitmapFactory.decodeStream(is);
   is.close();

  } catch (IOException e) {
   e.printStackTrace();
  }

  return bitmap;

 }


 @Override
 protected void onDestroy()
 {
  super.onDestroy();
  Intent intent = new Intent(this, PlayFileService.class);
  stopService(intent);
 }

 @Override
 public void onItemClick(AdapterView<?> arg0, View arg1, int arg2, long arg3) {
  // TODO Auto-generated method stub
  
 }

}

其中,returnBitMap(String url) 方法就是具体实现网络图片转换成bitmap。

 

Android显示网络图片Step2:

web_imageview_activity.xml

      android:layout_width="fill_parent" android:layout_height="fill_parent"
      android:orientation="vertical" android:background="@android:color/transparent"   >
   android:id="@+id/imgview"
 android:layout_width="wrap_content"  
 android:layout_height="wrap_content"  
 android:layout_gravity="center"   />

 

Android显示网络图片Step3:

在你的AndroidManifest.xml文件的< /manifest>节点上面添加

< uses-permission android:name="Android.permission.INTERNET" />,这是由于Android有很多的权限限制,否则图片是不能在你的模拟器上显示的。

 

 

http://www.189works.com/article-102567-1.html

 

http://www.189works.com/article-2612-1.html

 

http://wenku.baidu.com/view/1ecca51c964bcf84b9d57b80.html

更多相关文章

  1. android 中Drawable跟Bitmap转换及常用于图片相关操作方法 - And
  2. android带图片的AlertDialog和文件管理器(代码)
  3. android GridView实现选中图片放大。
  4. android 网络之 httppost
  5. Android中由于设置的背景图片太大导致OOM
  6. android操作系统默认的图片
  7. 2013.04.03——— android 图片缓存之二LruCache介绍

随机推荐

  1. JavaScript测试教程–part 4:模拟 API 调
  2. 服务端指南 数据存储篇 | MySQL(08) 分库与
  3. 常用数据结构的 JavaScript 实现代码[每
  4. JavaScript 测试教程–part 3:测试 props,
  5. 服务端指南 数据存储篇 | MySQL(09) 分库与
  6. 迈向 serverless 开发的第一步[每日前端
  7. android中导入低版本project
  8. package.json 详解[每日前端夜话0xEF]
  9. 聊聊 Redis 使用场景
  10. 04 管道、重定向和环境变量