B4J Code Snippet Draw arc line with round cap

Using jCanvasExt lib by @klaus to draw arc with rounded cap. To realize the sweep gradient, we use a conic gradient image as image pattern paint to draw, since javafx only provides linear or radial gradient.
Erel has one based on BitmapCreator which is nice as it is B4X, this one is based on javafx so B4J only. Hope it is still useful for someone to make progress bar or knob control view.

B4X:
    Private Cvx As CanvasExt
    Private Cv As Canvas
    Dim ip As JavaObject
    Dim im As Image = fx.LoadImage(File.DirAssets, "conic-gradient-full-example.png")
    ip.InitializeNewInstance("javafx.scene.paint.ImagePattern", Array(im, 0.0, 0.0, 400.0, 400.0, False))
    Cvx.Initialize(Cv)
    Cvx.SetLineCap("ROUND")
    Cvx.DrawArc2(200, 200, 160, 90, -225, "OPEN", ip, False, 40)

屏幕截图 2022-09-21 201151.png
 
Last edited:
Top