Android Question Question about DrawRectRounded2

Scantech

Well-Known Member
Licensed User
I just can't stop asking questions lol.

I am trying to get a good concept with this DrawRectRounded2. I was setting the filled to false and playing around with Strokewidth and Radius. I notice any Strokewidth value greater then Radius will fill the entire Rect. Basically, if i need a certain Strokewidth, the Radius value must be greater then Strokewidth? Is that how it works? increasing the value of strokewidth is out of wack in a sense.

The code i was playing around.
B4X:
Sub DrawRoundedRect(Width As Int, Height As Int, Radius As Int, Clrs() As Int, Orientation As String) As B4XBitmap
    Dim Gradient As BitmapCreator
    Gradient.Initialize(10, Height)
    Gradient.FillGradient(Clrs, Gradient.TargetRect, Orientation)
    Dim Brush As BCBrush = Gradient.CreateBrushFromBitmapCreator(Gradient)
    Dim bc As BitmapCreator
    bc.Initialize(Width, Height)
    bc.DrawRectRounded2(bc.TargetRect, Brush, False, 0, Radius)
    Return bc.Bitmap
End Sub
Thanks
 
Last edited:

klaus

Expert
Licensed User
Basically, if i need a certain Strokewidth, the Radius value must be greater then Strokewidth?
For me, this is a bug in the BitmapCreator library.

It works OK with the XUI library, with Path.InitializeRoundedRect and Canvas.DrawPath

Radius is the outer radius, independent of the StrokeWidth.
I suppose that the problem is the inner radius, which becomes <=0 when the StrokeWidth >= Radius.
 

Erel

Administrator
Staff member
Licensed User
The reason is coherence of the behaviour of similar methods.
Canvas and B4XCanvas are based on the native drawing APIs. They are "just" wrappers.

BitmapCreator is a drawing framework by itself. It is written in B4X. The drawing methods are implemented inside BitmapCreator class. Source code: https://www.b4x.com/android/forum/threads/b4x-x2-xui2d-box2d-game-engine.95208/page-2#post-622803
It is by far the most complicated B4X module that I wrote. It is the graphics engine behind XUI2D games which is quite impressive.
Drawing antialiased, non-thin shapes and with good performance is a challenging task.

I do plan to continue and improve BitmapCreator. You should expect some differences in edge cases between BitmapCreator drawings and the native drawings.
 
Top