我已经在我的 android 应用程序中成功集成了 facebook 登录。所以我正在显示用户个人资料数据,如姓名、电子邮件和图片。
现在我需要在数据库中存储用户数据,例如姓名、电子邮件和个人资料图片。我知道如何获取姓名和电子邮件,因为它可以从 TextViews 中获取。 但我正在努力获取个人资料照片。
个人资料图片使用 ProfilePictureView 显示。
我试图将 ProfilePictureView 上的图像转换为字节数组,但它不起作用。(通常这适用于 ImageView 和 Imagebuttons,但不适用于 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();
}
我得到的是这样的图片,而不是真实的个人资料照片。
有没有办法存储图像? (比如获取个人资料图片的链接,以便我以后可以使用该链接检索图像) 谢谢。
最佳答案
试试这个。它对我有用
private ProfilePictureView profilepic;
在 OnCreate 方法类型中:
profilepic = (ProfilePictureView) findViewById(R.id.<profilepicture id>);
profilepic.setProfileId(id of user (string));
希望对你有帮助
关于android - 如何从ProfilePictureView中获取头像存入数据库,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22171508/