user1202032
user1202032

Reputation: 1479

Drawing image with gradient tint and round corners

I'm trying to set a background on a view, which should be an image with a single rounded corner and a gradient tint overlayed

I feel like I'm close, I'm just missing the rounded corner. I have made a minimal working example project here: https://github.com/RandomStuffAndCode/AndroidCanvas

From https://github.com/RandomStuffAndCode/AndroidCanvas/blob/master/app/src/main/java/com/randomcodeandstuff/androidcanvas/MainActivity.java :

    RoundedBitmapDrawable dr = RoundedBitmapDrawableFactory.create(getResources(), src);
    dr.setCornerRadius(convertToPixels(context, CORNER_RADIUS));
    Bitmap drBitmap = drawableToBitmap(dr);
    Paint drPaint = new Paint();
    drPaint.setAntiAlias(true);
    drPaint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.SRC_IN));
    canvas.drawBitmap(drBitmap, 0,0,drPaint);

This obviously gives me 4 rounded corners instead of just 1. I considered drawing a rectangle on top of the other rounded corners, but because of the gradient overlay this does not look good.

How do i get rid of the 3 other rounded corners? Screenshot of the code here:Screenshot

Upvotes: 0

Views: 471

Answers (1)

Submersed
Submersed

Reputation: 8870

If you're targeting API level 21+, a possible option would be to use a normal ImageView, but set an ViewOutlineProvider on it. The Outline you provide will probably have to be the convexPath option, so you'd have to tinker with that for your specific use-case.

Upvotes: 1

Related Questions