简体   繁体   English

返回个人资料图片位图。 Facebook的Java

[英]Returning Profile Picture Bitmap. Facebook Java

I have Facebook graph requests working and seem to have no problem whatsoever, However I have been trying for a while to retrieve the profile picture. 我的Facebook图形请求有效,并且似乎没有任何问题,但是我已经尝试了一段时间来检索个人资料图片。 But everytime I run it the bitmap seems to turn out null. 但是每次我运行它时,位图似乎都为空。

 public static Bitmap DownloadImageBitmap(String url) {
    Bitmap bm = null;
    try {
        URL aURL = new URL(url);
        URLConnection conn = aURL.openConnection();
        conn.connect();
        InputStream is = conn.getInputStream();
        BufferedInputStream bis = new BufferedInputStream(is);
        bm = BitmapFactory.decodeStream(bis);
        bis.close();
        is.close();
    } catch (IOException e) {
        Log.e("IMAGE", "Error getting bitmap", e);
    }
    return bm;
}

For Example, If I feed it this string: String testString = "graph.facebook.com/849993771766163/picture?type=large"; 例如,如果我输入以下字符串:String testString =“ graph.facebook.com/849993771766163/picture?type=large”;

The bitmap will return null every single time.. 该位图将每次返回null。

What am I doing wrong? 我究竟做错了什么? I suspect I am getting the url wrong but I have tried everything 我怀疑自己输入的网址有误,但是我已经尝试了所有方法

Try replacing 尝试更换
bm = BitmapFactory.decodeStream(bis); bm = BitmapFactory.decodeStream(bis);
with
bm = Bitmap.createBitmap(BitmapFactory.decodeStream(bis)); bm = Bitmap.createBitmap(BitmapFactory.decodeStream(bis));

You may also need to create a scaled bitmap first and then set it to your final bitmap before setting it to a view. 您可能还需要先创建缩放位图,然后将其设置为最终位图,然后再将其设置为视图。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM