How to get the profile picture from ProfilePicture

2019-06-07 06:29发布

问题:

I have successfully integrated facebook login in my android app.So I am displaying user profile data like name,email and picture.

Now I need to store user data such as name,email and profile picture in database. I know how to get the name and email since it can be get from TextViews. But I am struggling to get the profile picture.

The profile picture is displayed using ProfilePictureView.

I tried to convert that image on ProfilePictureView to byte array, but it is not working.(Normally this works with ImageView ,Imagebuttons, but it is not working with ProfilePictureView)

    pic.setProfileId(user.getId());
    ImageView imageView = (ImageView)pic.getChildAt(0);
    Bitmap bmp = ((BitmapDrawable) imageView.getDrawable()).getBitmap();
    image_ = convertImageToByte(bmp); //image_ is a byte[]

    private byte[] convertImageToByte(Bitmap bitmap) {
       ByteArrayOutputStream stream = new ByteArrayOutputStream();
       bitmap.compress(Bitmap.CompressFormat.JPEG, 90, stream);
       return stream.toByteArray();
    }

I am getting an image like this instead of the real profile picture.

Is there anyway to store the image? (like a link to get the profile picture to store so I can retrieve the image using the link at later time) Thanks.

回答1:

Try this. It worked for me

private ProfilePictureView profilepic;

In OnCreate Method type:

profilepic = (ProfilePictureView) findViewById(R.id.<profilepicture id>);
profilepic.setProfileId(id of user (string));

Hope it helps



回答2:

i used this and it's working ok:

profileImageView = ((ImageView)faceBookProfilePictureView.getChildAt(0));
                            bitmap  = ((BitmapDrawable)profileImageView.getDrawable()).getBitmap();
                              circular.setImageBitmap(bitmap);

where "circular" it's CircularImageView Object.