Display FB profile pic in circular image view in Application

后端 未结 7 1182
刺人心
刺人心 2020-11-29 06:21

I am trying to get the profile pic of a user from FB and display it in a circular image on my app.I am able to retrieve and display the display pic in ProfilePictureView wid

7条回答
  •  南方客
    南方客 (楼主)
    2020-11-29 06:46

    I spent quite a bit of time investigating the options for displaying a circular Facebook profile image and I think it's easiest to leave the Android SDK aside and just leverage your existing image library's transformations.

    Instead of using Facebook's ProfilePictureView, use ImageView. Then, load the image with Picasso, Glide, or whatever library you prefer. Below I'm using Picasso with Picasso-Transformations.

    Now:

    ImageView profilePic = (ImageView) findViewById(R.id.ivProfilePic);
    
    Picasso.with(this)
         .load("https://graph.facebook.com/v2.2/" + user.getUserId() + "/picture?height=120&type=normal") //extract as User instance method
         .transform(new CropCircleTransformation())
         .resize(120, 120)
         .into(profilePic);
    

    Before:

    ProfilePictureView profilePic = (ProfilePictureView)findViewById(R.id.ivProfilePic);
    profilePic.setProfileId(user.getUserId());
    //custom transformation code
    
    • https://github.com/wasabeef/picasso-transformations
    • https://developers.facebook.com/docs/graph-api/reference/user/picture/

提交回复
热议问题