2015-03-25 44 views
0

我從Facebook SDK獲取配置文件圖像,它會返回我url。當我在瀏覽器中打開它時,會顯示圖像。但是當我將它轉換成位圖時,它會返回null。這裏是我的代碼:圖片URL的位置

String id = user.getId(); 
try { 
     URL image_path = new URL("http://graph.facebook.com/"+ id+ "/picture?type=large"); 
     Bitmap profPict = BitmapFactory.decodeStream(image_path.openConnection().getInputStream()); 
     System.out.println("profPict::> " + profPict); 
     ImageView img= (ImageView)findViewById(R.id.textView2); 
     img.setImageBitmap(profPict); 
     System.out.println("image::> " + image_path); 
} 
catch (Exception e) { 
     e.printStackTrace(); 
} 
+0

使用此鏈接 [1]:http://stackoverflow.com/questions/19175133/how-to-set-a-image-to-a-image-view-from-a-url-安卓 – Minp 2015-03-25 06:07:14

回答

0
public Bitmap getBitmapFromURL(String srcurl){ 
     try { 
      URL url = new URL(src); 
      HttpURLConnection connection=(HttpURLConnection)url.openConnection(); 
      connection.setDoInput(true); 
      connection.connect(); 
      InputStream input=connection.getInputStream(); 
      Bitmap myBitmap=BitmapFactory.decodeStream(input); 
      return myBitmap; 
     } catch (IOException e) { 
      e.printStackTrace(); 
      return null; 
     } 
    } 
0

使用任何可用的第三方庫將接受URL和ImageView的,並會在ImageView的下載和設置圖像。

Android Universal Image Loader非常有用。