您好我正在尝试从网址获取Bitmap
,此网址会重定向到另一个https网址。
网址:http://graph.facebook.com/244054592454345/picture
我正在尝试获取下面的位图,但这对我不起作用,试过这个Android : Getting a Bitmap from a url connection (graph.facebook.com) that redirects to another url但不适用于我。
使用下面的代码,我总是在位图中得到null。
URL imgUrl = new URL("http://graph.facebook.com/{user-id}/picture?type=large");
InputStream in = (InputStream) imgUrl.getContent();
Bitmap bitmap = BitmapFactory.decodeStream(in);
有没有想过从像我这样重定向到另一个链接的链接获取位图?
答案 0 :(得分: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();