How to get the profile picture from ProfilePictureView to store in the database

我怕爱的太早我们不能终老 提交于 2020-01-14 05:05:31

问题


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.



来源:https://stackoverflow.com/questions/22171508/how-to-get-the-profile-picture-from-profilepictureview-to-store-in-the-database

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!