Android Question Creating a transparent overlay with rounded corners

Martin Larsen

Active Member
Licensed User
Longtime User
As stated in this post I need to make an image slider with rounded corners. That catch is that there are some rotated and shaded labels over the images and these should have round corners as well. On this sceendump the label corners are not rounded because only the images themselves are rounded.

screenshot-2019-12-18_21-13-11-435-png.86474


The solution I found worked best is to simply overlay the whole bunch with a transparent mask as shown below:
overlay-png.86473


Now, this is quite tedious to create and takes a bit trial and error, so how do I create this programmatically?

My guess is that a modified version of CreateRoundRectBitmap should be able to do it.
 

sorex

Expert
Licensed User
Longtime User
yes, first rectfill with blue then draw the rounded rectangle with colors.transparent.

that way you can have your bend always correct and sharp unlike resizing a premade image.
 
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
java_tWBpgif0m6.png


B4X:
Sub CreateEdge (BackgroundBitmap As B4XBitmap, TargetView As B4XView)
    Dim bc As BitmapCreator
    bc.Initialize(TargetView.Width, TargetView.Height)
    bc.CopyPixelsFromBitmap(BackgroundBitmap)
    bc.DrawRectRounded(bc.TargetRect, xui.Color_Transparent, True, 0, 20dip)
    bc.SetBitmapToImageView(bc.Bitmap, TargetView)
End Sub

B4J example is attached.
 

Attachments

  • 1.zip
    2.2 KB · Views: 332
Upvote 0

Martin Larsen

Active Member
Licensed User
Longtime User
Thanks, Erel, it works perfectly. The antialiasing is not a problem at all, you don't notice it on the phone. You have to make a screendump and zoom in to see it.
 
Upvote 0
Top