网图片查看器

public void on(View view){
      //获取网络图片的地址
       String path="http://192.168.1.6:8080/Image/meinv.jpg";
       //发送http请求
    try {
       //使用网址构建一个URL对象
      URL url=new URL(path);
       //获取连接对象
       HttpURLConnection http=(HttpURLConnection) url.openConnection();
      //设置一些属性
      //设置请求方式,注意大写
       http.setRequestMethod("GET");
      //设置请求超时
      http.setConnectTimeout(8000);
      //设置读取超时
      http.setReadTimeout(8000);
      //发送请求,建立连接
      http.connect();
      //判断响应码是否为200
  if(http.getResponseCode()==200){
      //获取服务器返回的图片
      InputStream in=http.getInputStream();
         //把图片封装在位图里面
         Bitmap bitmap=BitmapFactory.decodeStream(in);
           ImageView imageView=(ImageView) findViewById(R.id.imageView1);
        //把位图图片放到Imageview里显示
            imageView.setImageBitmap(bitmap);
  }else{
        Toast.makeText(this,"请求失败!", 1).show();
  }
  } catch (Exception e) {
    // TODO Auto-generated catch block
    e.printStackTrace();
  }
 }

posted @ 2015-12-06 10:40  随笔、  阅读(493)  评论(0编辑  收藏  举报