获取用户个人资料图片圈图像视图
问题描述:
我已经实施Facebook登录到我的应用程序,现在想要获得用户个人资料图片,我已经做了这个,但我现在试图把它变成一个圆形格式使用此库 - https://github.com/vinc3m1/RoundedImageView获取用户个人资料图片圈图像视图
我有实现两者结合起来麻烦,我不知道最好的方式去解决它
这里是java
final RoundedImageView profilePic = (RoundedImageView) rootView.findViewById(R.id.myProfilePic);
GraphRequestAsyncTask request = GraphRequest.newMeRequest(AccessToken.getCurrentAccessToken(), new GraphRequest.GraphJSONObjectCallback() {
@Override
public void onCompleted(JSONObject user, GraphResponse response) {
if (user != null) {
// set the profile picture using their Facebook ID
profilePic.setProfileId(user.optString("id"));
}
}
}).executeAsync();
这里是XML
<com.makeramen.roundedimageview.RoundedImageView
android:id="@+id/myProfilePic"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="40dp"
android:layout_gravity="center_horizontal"
android:padding="10dip"
android:scaleType="center"
app:riv_corner_radius="30dip"
app:riv_border_width="3dip"
app:riv_oval="false"
app:riv_border_color="@color/material_white"
/>
我收到错误
无法解析法“SetProfileId”
我认为错误是因为我没有在图形请求返回了相应的位图,但不知道如何解决此问题。
答
看着RoundedImageView
来源我没有看到任何方法setprofileId()
。您需要向Facebook Graph API发送请求以获取个人资料图片的URL,然后将其交给视图(如果它具有此类方法),或者自行下载并将其作为Bitmap
传递给视图。
答
可以实现用毕加索
下同是代码:
Picasso.with(context).load(imageURL)
.error(drawable)
.placeholder(drawable)
.transform(new RoundedTransformation()).into(imgView);
public class RoundedTransformation implements Transformation {
@Override
public Bitmap transform(Bitmap source) {
try {
int size = Math.min(source.getWidth(), source.getHeight());
int x = (source.getWidth() - size)/2;
int y = (source.getHeight() - size)/2;
Bitmap squaredBitmap = Bitmap
.createBitmap(source, x, y, size, size);
if (squaredBitmap != source) {
source.recycle();
}
Bitmap bitmap = Bitmap.createBitmap(size, size, source.getConfig());
Canvas canvas = new Canvas(bitmap);
Paint paint = new Paint();
BitmapShader shader = new BitmapShader(squaredBitmap,
BitmapShader.TileMode.CLAMP, BitmapShader.TileMode.CLAMP);
paint.setShader(shader);
paint.setAntiAlias(true);
float r = size/2f;
canvas.drawCircle(r, r, r, paint);
squaredBitmap.recycle();
return bitmap;
} catch (Exception e) {
// TODO: handle exception
if (BuildConfig.DEBUG)
e.printStackTrace();
return null;
}
}
@Override
public String key() {
return "circle";
}
}
感谢您的回复,我很感兴趣,下载它自己,因为我认为这将是更容易与工作,但我无法找到任何信息如何做到这一点。你认为做这件事最好的方法是什么? –
看看你如何使用图形API获取URL - https://developers.facebook.com/docs/graph-api/reference/profile-picture-source/ –
Thankyou帮助我实际上设法通过获取通过Graph Request的uri,然后将其提交给Facebooks壁画,该壁纸具有用于将图像转换为圆形的内置方法。 –