【问题标题】:Android - BitMap Null From URL [duplicate]Android - 来自 URL 的位图 Null [重复]
【发布时间】:2014-09-01 00:02:00
【问题描述】:

当我试图从 facebook url 获取位图图像时,它显示位图为空。这是我的代码。

URL url = new URL("http://graph.facebook.com/100006480449004/picture?type=large");
HttpURLConnection connection = (HttpURLConnection) url.openConnection();
connection.setDoInput(true);
connection.connect();
InputStream input = connection.getInputStream();
Bitmap myBitmap = BitmapFactory.decodeStream(input);

【问题讨论】:

  • 这里显然有一个重定向。您可能需要告诉 httpUrlConnection 跟随它。

标签: android bitmap


【解决方案1】:

在浏览器中输入网址,这会将您转到正确的图片网址,以.jpg结尾

或者您通过connection.setInstanceFollowRedirects(true);启用重定向

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-08-23
    • 2014-09-14
    • 1970-01-01
    相关资源
    最近更新 更多