Android:从重定向到另一个网址的url连接(graph.facebook.com)获取位图 [英] Android : Getting a Bitmap from a url connection (graph.facebook.com) that redirects to another url
问题描述
我已经做了一切,获得一个网址,我可以获得Facebook用户的个人资料图片。
I have done everything to get a url where i can get the profile pic of a facebook user.
现在唯一的问题是将该图像变成位图对象。
The only problem left now is to get that image into a bitmap object.
自从 http://graph.facebook.com 现在将连接首先重定向(如我们在url中可以看到的) https:// fbcdn -profile-a.akamaihd.net/ ...(这样的东西)。
Since, http://graph.facebook.com now redirects the connection first (as we can see in the url) to https://fbcdn-profile-a.akamaihd.net/... (something like this).
所以,我想问一下如何获得位图从网址: http://graph.facebook.com/ ...
重定向 https://fbcdn-profile-a.akamaihd.net/ ...
So, i wanted to ask as to how can i get the bitmap from the url : http://graph.facebook.com/... that redirects to https://fbcdn-profile-a.akamaihd.net/...
推荐答案
你是正确的说 http://graph.facebook.com 首先重定向连接(我们可以这样做) ee in the url)to https://fbcdn-profile-a.akamaihd.net/,但是 -
You are right in saying that http://graph.facebook.com redirects the connection first (as we can see in the url) to https://fbcdn-profile-a.akamaihd.net/, but-
当原始和重定向协议相同时,自动重定向将自动工作。
auto redirection works automatically when original and redirected protocols are same.
因此,如果您尝试从 https 加载图片,而不是http: https://graph.facebook.com/USER_ID/picture ;因为图片的网址是 https://fbcdn-profile-a.akamaihd.net/ ...., BitmapFactory.decodeStream
将再次工作,让您得到位图。
So, if you try to load images from https instead of http : "https://graph.facebook.com/USER_ID/picture"; since image's url is "https://fbcdn-profile-a.akamaihd.net/....", BitmapFactory.decodeStream
shall work again to get you the bitmap.
URL imgUrl = new URL("https://graph.facebook.com/{user-id}/picture?type=large");
InputStream in = (InputStream) imgUrl.getContent();
Bitmap bitmap = BitmapFactory.decodeStream(in);
希望有所帮助。祝你好运。
Hope that helps. Good luck.
这篇关于Android:从重定向到另一个网址的url连接(graph.facebook.com)获取位图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!