2015-07-09 117 views
1

我已經實施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」

我認爲錯誤是因爲我沒有在圖形請求返回了相應的位圖,但不知道如何解決此問題。

回答

1

看着RoundedImageView來源我沒有看到任何方法setprofileId()。您需要向Facebook Graph API發送請求以獲取個人資料圖片的URL,然後將其交給視圖(如果它具有此類方法),或者自行下載並將其作爲Bitmap傳遞給視圖。

+0

感謝您的回覆,我很感興趣,下載它自己,因爲我認爲這將是更容易與工作,但我無法找到任何信息如何做到這一點。你認爲做這件事最好的方法是什麼? –

+0

看看你如何使用圖形API獲取URL - https://developers.facebook.com/docs/graph-api/reference/profile-picture-source/ –

+1

Thankyou幫助我實際上設法通過獲取通過Graph Request的uri,然後將其提交給Facebooks壁畫,該壁紙具有用於將圖像轉換爲圓形的內置方法。 –

0

可以實現用畢加索

下同是代碼:

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"; 
} 

}