Android Question B4XCanvas rounded square corners

Scantech

Well-Known Member
Licensed User
Longtime User
How do I draw rounded square corners with 2 gradient color in B4Xcanvas?

Thanks
 

Erel

B4X founder
Staff member
Licensed User
Longtime User
You should use BitmapCreator for this:
B4X:
Sub Globals
   Private xui As XUI
   Private ImageView1 As ImageView
End Sub

Sub Activity_Create(FirstTime As Boolean)
   Activity.LoadLayout("1")
   Dim bmp As B4XBitmap = DrawRoundedRect(ImageView1.Width, ImageView1.Height, 5dip, Array As Int(xui.Color_Blue, xui.Color_Yellow))
   ImageView1.SetBackgroundImage(bmp)
End Sub

Sub DrawRoundedRect(Width As Int, Height As Int, Radius As Int, Clrs() As Int) As B4XBitmap
   Dim Gradient As BitmapCreator
   Gradient.Initialize(10, Height)
   Gradient.FillGradient(Clrs, Gradient.TargetRect, "TOP_BOTTOM")
   Dim Brush As BCBrush = Gradient.CreateBrushFromBitmapCreator(Gradient)
   Dim bc As BitmapCreator
   bc.Initialize(Width, Height)
   bc.DrawRectRounded2(bc.TargetRect, Brush, True, 0, Radius)
   Return bc.Bitmap
End Sub

You can reuse the brush.
 
Upvote 0
Top