Skip to content

Instantly share code, notes, and snippets.

@kaushikgopal
Last active March 25, 2024 13:55

Revisions

  1. kaushikgopal revised this gist Nov 21, 2016. 1 changed file with 2 additions and 2 deletions.
    4 changes: 2 additions & 2 deletions RoundedBitmapDrawableUsage.java
    Original file line number Diff line number Diff line change
    @@ -1,10 +1,10 @@
    Bitmap batmapBitmap = BitmapFactory.decodeResource(getResources(), R.drawable.batman);
    RoundedBitmapDrawable circularBitmapDrawable = RoundedBitmapDrawableFactory.create(getResources(), batmapBitmap);

    // mechanism 1 h/t [Chris Banes](https://chris.banes.me/)
    // option 1 h/t [Chris Banes](https://chris.banes.me/)
    circularBitmapDrawable.setCornerRadius(batmapBitmap.getWidth());

    // mechanism 2 h/t @csorgod in the comments
    // option 2 h/t @csorgod in the comments
    circularBitmapDrawable.setCircular(true);


  2. kaushikgopal revised this gist Nov 21, 2016. 1 changed file with 6 additions and 13 deletions.
    19 changes: 6 additions & 13 deletions RoundedBitmapDrawableUsage.java
    Original file line number Diff line number Diff line change
    @@ -1,19 +1,12 @@
    Bitmap batmapBitmap = BitmapFactory.decodeResource(getResources(), R.drawable.batman);
    RoundedBitmapDrawable circularBitmapDrawable = RoundedBitmapDrawableFactory.create(getResources(), batmapBitmap);

    RoundedBitmapDrawable circularBitmapDrawable = //
    RoundedBitmapDrawableFactory.create(getResources(), batmapBitmap);

    // mechanism 1 h/t [Chris Banes](https://chris.banes.me/)
    circularBitmapDrawable.setCornerRadius(batmapBitmap.getWidth());

    myImageView.setImageDrawable(circularBitmapDrawable);

    System.out.prinln("MyActivity", "That's all folks");

    /*
    // mechanism 2 h/t @csorgod in the comments
    circularBitmapDrawable.setCircular(true);

    Hat tip to the amazing [Chris Banes](https://chris.banes.me/)
    for pointing out [RoundedBitmapDrawable in the support libs](https://developer.android.com/reference/android/support/v4/graphics/drawable/RoundedBitmapDrawable.html)

    While this is now super simple to do, I would encourage you to
    read Evelio's blog post http://evel.io/2013/07/21/rounded-avatars-in-android/
    as it'll help you gain a good understanding of drawable/bitmap manipulation */
    myImageView.setImageDrawable(circularBitmapDrawable);
    System.out.prinln("MyActivity", "That's all folks");
  3. kaushikgopal revised this gist Feb 26, 2015. 1 changed file with 8 additions and 6 deletions.
    14 changes: 8 additions & 6 deletions RoundedBitmapDrawableUsage.java
    Original file line number Diff line number Diff line change
    @@ -1,6 +1,3 @@
    // hat tip to the amazing [Chris Banes](https://chris.banes.me/)
    // for pointing out the existance of [RoundedBitmapDrawable in the support libs](https://developer.android.com/reference/android/support/v4/graphics/drawable/RoundedBitmapDrawable.html)

    Bitmap batmapBitmap = BitmapFactory.decodeResource(getResources(), R.drawable.batman);

    RoundedBitmapDrawable circularBitmapDrawable = //
    @@ -12,6 +9,11 @@

    System.out.prinln("MyActivity", "That's all folks");

    // While this is now super simple to do, I would encourage you to:
    // 1. read Evelio's blog post http://evel.io/2013/07/21/rounded-avatars-in-android/ (excellent for understanding different approaches)
    // 2. See Vince's code in this library https://github.com/vinc3m1/RoundedImageView
    /*
    Hat tip to the amazing [Chris Banes](https://chris.banes.me/)
    for pointing out [RoundedBitmapDrawable in the support libs](https://developer.android.com/reference/android/support/v4/graphics/drawable/RoundedBitmapDrawable.html)
    While this is now super simple to do, I would encourage you to
    read Evelio's blog post http://evel.io/2013/07/21/rounded-avatars-in-android/
    as it'll help you gain a good understanding of drawable/bitmap manipulation */
  4. kaushikgopal revised this gist Feb 23, 2015. 1 changed file with 7 additions and 4 deletions.
    11 changes: 7 additions & 4 deletions RoundedBitmapDrawableUsage.java
    Original file line number Diff line number Diff line change
    @@ -2,13 +2,16 @@
    // for pointing out the existance of [RoundedBitmapDrawable in the support libs](https://developer.android.com/reference/android/support/v4/graphics/drawable/RoundedBitmapDrawable.html)

    Bitmap batmapBitmap = BitmapFactory.decodeResource(getResources(), R.drawable.batman);

    RoundedBitmapDrawable circularBitmapDrawable = //
    RoundedBitmapDrawableFactory.create(getResources(), batmapBitmap);

    circularBitmapDrawable.setCornerRadius(batmapBitmap.getWidth());

    myImageView.setImageDrawable(circularBitmapDrawable);

    // That's all folks!
    System.out.prinln("MyActivity", "That's all folks");

    // for an indepth understanding of how this was otherwise usually done, see
    // 1. http://evel.io/2013/07/21/rounded-avatars-in-android/
    // 2. https://github.com/vinc3m1/RoundedImageView
    // While this is now super simple to do, I would encourage you to:
    // 1. read Evelio's blog post http://evel.io/2013/07/21/rounded-avatars-in-android/ (excellent for understanding different approaches)
    // 2. See Vince's code in this library https://github.com/vinc3m1/RoundedImageView
  5. kaushikgopal revised this gist Feb 23, 2015. 1 changed file with 5 additions and 5 deletions.
    10 changes: 5 additions & 5 deletions RoundedBitmapDrawableUsage.java
    Original file line number Diff line number Diff line change
    @@ -1,11 +1,11 @@
    // hat tip to the amazing [Chris Banes](https://chris.banes.me/)
    // for pointing out the existance of [RoundedBitmapDrawable in the support libs](https://developer.android.com/reference/android/support/v4/graphics/drawable/RoundedBitmapDrawable.html)

    Bitmap batmapBitmap = BitmapFactory.decodeResource(getResources(), R.drawable.batman);
    RoundedBitmapDrawable circularBitmapDrawable = //
    RoundedBitmapDrawableFactory.create(getResources(), batmapBitmap);
    circularBitmapDrawable.setCornerRadius(batmapBitmap.getWidth());
    myImageView.setImageDrawable(circularBitmapDrawable);
    Bitmap batmapBitmap = BitmapFactory.decodeResource(getResources(), R.drawable.batman);
    RoundedBitmapDrawable circularBitmapDrawable = //
    RoundedBitmapDrawableFactory.create(getResources(), batmapBitmap);
    circularBitmapDrawable.setCornerRadius(batmapBitmap.getWidth());
    myImageView.setImageDrawable(circularBitmapDrawable);

    // That's all folks!

  6. kaushikgopal created this gist Feb 23, 2015.
    14 changes: 14 additions & 0 deletions RoundedBitmapDrawableUsage.java
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,14 @@
    // hat tip to the amazing [Chris Banes](https://chris.banes.me/)
    // for pointing out the existance of [RoundedBitmapDrawable in the support libs](https://developer.android.com/reference/android/support/v4/graphics/drawable/RoundedBitmapDrawable.html)

    Bitmap batmapBitmap = BitmapFactory.decodeResource(getResources(), R.drawable.batman);
    RoundedBitmapDrawable circularBitmapDrawable = //
    RoundedBitmapDrawableFactory.create(getResources(), batmapBitmap);
    circularBitmapDrawable.setCornerRadius(batmapBitmap.getWidth());
    myImageView.setImageDrawable(circularBitmapDrawable);

    // That's all folks!

    // for an indepth understanding of how this was otherwise usually done, see
    // 1. http://evel.io/2013/07/21/rounded-avatars-in-android/
    // 2. https://github.com/vinc3m1/RoundedImageView