Search code examples
androidcanvasandroid-canvasandroid-drawableandroid-bitmap

individual rounded corners (NOT all corners)


I'm trying to get rounded corners on the TOP corners of a bitmap only. Using RoundedBitmapDrawable i can get rounded corners on all corners but how can i get it on only the top ones?

Code i'm using to get all corners rounded:

Bitmap src = BitmapFactory.decodeResource(getResources(), R.drawable.login_background, options);
RoundedBitmapDrawable dr = RoundedBitmapDrawableFactory.create(getResources(), src);
dr.setCornerRadius(convertToPixels(context, CORNER_RADIUS));
myView.setBackground(dr);

Solution

  • You can make this using Glide transformations.

    RoundedCornersTransformation actually can round all corners with the same radius (not solving your issue).
    But i probably would recommend you to use MaskTransformation. Draw 9-patch drawable with required rounded corners and pass it to the transformation.

    Also you can try writing your own custom Glide transformation (copying or extending RoundedCornersTransformation): https://github.com/bumptech/glide/wiki/Transformations