【问题标题】:How to get Bitmap from URL that redirect to https URL如何从重定向到 https URL 的 URL 获取位图
【发布时间】:2014-05-09 12:15:05
【问题描述】:

您好,我正在尝试从 URL 获取 Bitmap,此 URL 正在重定向到另一个 https URL。

网址:http://graph.facebook.com/244054592454345/picture

我正在尝试获取如下所示的位图,但这对我不起作用,尝试了 Android : Getting a Bitmap from a url connection (graph.facebook.com) that redirects to another url 但对我不起作用。

使用下面的代码,我总是在位图中得到空值。

URL imgUrl = new URL("http://graph.facebook.com/{user-id}/picture?type=large");
InputStream in = (InputStream) imgUrl.getContent();
Bitmap  bitmap = BitmapFactory.decodeStream(in);

任何想法从一个链接中获取位图,并像我一样重定向到另一个链接?

【问题讨论】:

    标签: android facebook facebook-graph-api bitmap url-redirection


    【解决方案1】:

    下面的代码解决了我的问题并且工作正常。

    URL fbAvatarUrl = new URL("http://graph.facebook.com/"+userProfileModel.getFacebookID()+"/picture");
    HttpGet httpRequest = new HttpGet(fbAvatarUrl.toString()); 
    DefaultHttpClient httpclient = HttpClient.getInstance(); 
    HttpResponse response = (HttpResponse) httpclient.execute(httpRequest);
    HttpEntity entity = response.getEntity(); 
    BufferedHttpEntity bufHttpEntity = new BufferedHttpEntity(entity); 
    Bitmap  fbAvatarBitmap = BitmapFactory.decodeStream(bufHttpEntity.getContent());
    httpRequest.abort();
    

    【讨论】:

      猜你喜欢
      • 2020-08-07
      • 2014-05-20
      • 1970-01-01
      • 2018-06-25
      • 2013-02-24
      • 2012-02-26
      • 2018-04-17
      • 2016-12-11
      相关资源
      最近更新 更多