Android Code Snippet [B4X] [XUI] Faster* DrawPolygon Method

Discussion in 'Code Snippets' started by Erel, Jun 24, 2018.

  1. Erel

    Erel Administrator Staff Member Licensed User

    You can draw polygons with B4XCanvas.DrawPath. The following code calls B4XCanvas.DrawPath on B4A and B4i and calls a different method in B4J. DrawPath in B4J is slower than the other drawing methods as it requires clipping the canvas (it is only required in B4J).

    To summarize, only use this code if you encountered a performance issue with B4XCanvas.DrawPath in B4J:

    Sub Page1_Click
    Array (Array As Int(100dip100dip), Array As Int(200dip0), _
    Array As Int (300dip100dip), Array As Int(200dip200dip), Array As Int(100dip100dip)), _
    End Sub

    Sub DrawPolygon (cvs1 As B4XCanvas, Points As List, Color As Int, Filled As Boolean, StrokeWidth As Double)
    If Points.Size < 1 Then Return
    #if B4A or B4i
    Dim FirstPoint() As Int = Points.Get(0)
    Dim p As B4XPath
    0), FirstPoint(1))
    For i = 1 To Points.Size - 1
    Dim point() As Int = Points.Get(i)
    point(0), point(1))
       cvs1.DrawPath(p, Color, Filled, StrokeWidth)
    Dim jcvs As JavaObject = cvs1
       jcvs = jcvs.GetFieldJO(
    Dim xpoints(Points.Size), ypoints(Points.Size) As Double
    For i = 0 To Points.Size - 1
    Dim point() As Int = Points.Get(i)
           xpoints(i) = 
           ypoints(i) = 
    Dim paint As Object = fx.Colors.From32Bit(Color)
    If Filled Then
    "fillPolygon"Array(xpoints, ypoints, Points.Size))
    "strokePolygon"Array(xpoints, ypoints, Points.Size))
    End If
    #End If
    End Sub
  2. Star-Dust

    Star-Dust Expert Licensed User

    Why not edit jXUI library and have this method already integrated into jB4XCanvas class?
    ivan.tellez likes this.
  3. OliverA

    OliverA Expert Licensed User

    Erel likes this.
  4. Star-Dust

    Star-Dust Expert Licensed User

    Is it already included in XUI library 1.72?
  5. Erel

    Erel Administrator Staff Member Licensed User

    You can see the available methods in the IDE. It is not included.
    Star-Dust likes this.
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice