gpt4 book ai didi

Android : Getting a Bitmap from a url connection (graph. facebook.com)重定向到另一个网址

转载 作者:太空宇宙 更新时间:2023-11-03 11:49:54 25 4
gpt4 key购买 nike

我已尽一切努力获得一个 url,我可以在其中获取 facebook 用户的个人资料照片。

现在剩下的唯一问题是将该图像放入位图对象中。

因为,http://graph.facebook.com现在首先将连接重定向(正如我们在 url 中看到的那样)到 https://fbcdn-profile-a.akamaihd.net/ ...(类似这样的事情)。

所以,我想问一下如何从 url 获取位图:http://graph.facebook.com/ ...重定向到 https://fbcdn-profile-a.akamaihd.net/ ...

最佳答案

你说得对 http://graph.facebook.com首先将连接重定向(正如我们在 url 中看到的那样)到 https://fbcdn-profile-a.akamaihd.net/ , 但是-

auto redirection works automatically when original and redirected protocols are same.

因此,如果您尝试从 https 而不是 http 加载图像:“https://graph.facebook.com/USER_ID/picture ”;由于图像的 url 是“https://fbcdn-profile-a.akamaihd.net/ ....”,BitmapFactory.decodeStream 将再次工作以获取位图。

这是代码-

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

希望对您有所帮助。祝你好运。

关于Android : Getting a Bitmap from a url connection (graph. facebook.com)重定向到另一个网址,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22928137/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com