Display FB profile pic in circular image view in Application

后端 未结 7 1192
刺人心
刺人心 2020-11-29 06:21

I am trying to get the profile pic of a user from FB and display it in a circular image on my app.I am able to retrieve and display the display pic in ProfilePictureView wid

7条回答
  •  臣服心动
    2020-11-29 06:34

    I found a helpful working code here. Hope it helps. http://curious-blog.blogspot.in/2014/05/create-circle-bitmap-in-android.html

    activity_main.xml

     
    
        
    
        
    

    getCircleBitmap function

        private Bitmap getCircleBitmap(Bitmap bitmap) {
        final Bitmap output = Bitmap.createBitmap(bitmap.getWidth(),
        bitmap.getHeight(), Bitmap.Config.ARGB_8888);
        final Canvas canvas = new Canvas(output);
    
     final int color = Color.RED;
     final Paint paint = new Paint();
     final Rect rect = new Rect(0, 0, bitmap.getWidth(), bitmap.getHeight());
     final RectF rectF = new RectF(rect);
    
     paint.setAntiAlias(true);
     canvas.drawARGB(0, 0, 0, 0);
     paint.setColor(color);
     canvas.drawOval(rectF, paint);
    
     paint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.SRC_IN));
     canvas.drawBitmap(bitmap, rect, rect, paint);
    
     bitmap.recycle();
    
     return output;
    }
    

    MainActivity Class

      @Override
    protected void onCreate(Bundle savedInstanceState) {
     super.onCreate(savedInstanceState);
     setContentView(R.layout.activity_main);
    
     // create bitmap from resource
     Bitmap bm = BitmapFactory.decodeResource(getResources(),
      R.drawable.simple_image);
    
     // set circle bitmap
     ImageView mImage = (ImageView) findViewById(R.id.image);
     mImage.setImageBitmap(getCircleBitmap(bm));
    
    }
    

提交回复
热议问题