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.
 
Code:
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
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


Code:
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
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
Simple:

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


Code:
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.
 
  • Like
Reactions: byz
Upvote 0

Similar Threads

Replies
12
Views
5K
  • Question Question
Android Question Add Arc to Path
Replies
7
Views
5K
  • Article Article
Android Code Snippet Draw round bitmap
Replies
6
Views
15K
Back
Top