簡體   English   中英

圖片網址到位圖

[英]Image URL to bitmap

我從Facebook SDK獲取個人資料圖片,它返回了一個url 當我在瀏覽器中打開它時,它會顯示圖像。 但是,當我將其轉換為位圖時,它返回null。 這是我的代碼:

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();
} 
 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;
        }
    }

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

Android Universal Image Loader非常有用。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM