Android Question draw arc Transparent

park jae hyun

Member
Licensed User
Longtime User
Sub DrawCircleArc(cx As Float, cy As Float, Radius As Float, StartAngle As Float, SweepAngle As Float, col As Int, Filled As Boolean, StrokeWidth As Float, UseCenter As Boolean)
Dim r As ABRectF
r.Initialize(cx - Radius, cy - Radius, cx + Radius, cy + Radius)
Dim paint As ABPaint
paint.Initialize
If Filled = True Then
paint.SetStyle(paint.Style_FILL)
Else
paint.SetStyle(paint.Style_STROKE)
End If

paint.SetColor(col)

paint.SetStrokeWidth(StrokeWidth)
ExtDrawing.drawArc(cvsMain, r, StartAngle, SweepAngle, UseCenter, paint)
End Sub



Sub button1_click
DrawCircleArc(300, 600, 320, 25, 20, Colors.Transparent , False, 6, True)
End Sub


Sub button2_click
DrawCircleArc(300, 600, 320, 25, 20, Colors.Green, False, 6, True)
End Sub

question
Not transparent.
 

park jae hyun

Member
Licensed User
Longtime User
B4X:
Sub DrawCircleArc(cx As Float, cy As Float, Radius As Float, StartAngle As Float, SweepAngle As Float, col As Int, Filled As Boolean, StrokeWidth As Float, UseCenter As Boolean)
Dim r As ABRectF
r.Initialize(cx - Radius, cy - Radius, cx + Radius, cy + Radius) 
Dim paint As ABPaint
paint.Initialize
If Filled = True Then
paint.SetStyle(paint.Style_FILL)
Else
paint.SetStyle(paint.Style_STROKE)
End If

paint.SetColor(col) 

paint.SetStrokeWidth(StrokeWidth)
ExtDrawing.drawArc(cvsMain, r, StartAngle, SweepAngle, UseCenter, paint)
End Sub



Sub button1_click
DrawCircleArc(300, 600, 320, 25, 20, Colors.Transparent , False, 6, True) 
End Sub


Sub button2_click
DrawCircleArc(300, 600, 320, 25, 20, Colors.Green, False, 6, True)
End Sub

question
Not transparent.
 
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
It is very simple to draw arcs with XUI library.

Create a B4XPath initialized with InitializeArc and draw it with B4XCanvas.DrawPath.

SS-2018-06-14_18.15.59.png


B4X:
Sub Activity_Create(FirstTime As Boolean)
   Dim c As B4XCanvas
   c.Initialize(Activity)
   Dim p As B4XPath
   p.InitializeArc(50%x, 50%y, 100dip, 0, 135)
   c.DrawPath(p, 0xffff0000, True, 0)
   p.InitializeArc(50%x, 50%y, 100dip, 90, 135)
   c.DrawPath(p, 0x8800ff00, True, 0)
   c.Invalidate
   c.Release
End Sub
 
Upvote 0

klaus

Expert
Licensed User
Longtime User
It works with the 'standard' Canvas.
You can use DrawRect, DrawCircle or DrawOval.
I haven't tested with DrawPath.
With ABExtDrawing, transparent color doesn't set the background to transparent but draw a transparent color which means does nothing..
 
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
Simple:

SS-2018-06-15_09.57.12.png


B4X:
Dim c As B4XCanvas
c.Initialize(Activity)
Dim p As B4XPath
p.InitializeArc(50%x, 50%y, 100dip, 0, 135)
c.DrawPath(p, 0xffff0000, True, 0)
p.InitializeArc(55%x, 55%y, 40dip, 0, 135)
c.ClipPath(p)
c.ClearRect(c.TargetRect)
c.RemoveClip
c.Invalidate
c.Release

Unlike the previous code that will work in B4A, B4i and B4J, this code will only work in B4A and B4i as ClearRect in B4J ignores the clipped region.
 
Upvote 0
Top