Android Question draw arc Transparent

Discussion in 'Android Questions' started by park jae hyun, Jun 14, 2018.

  1. park jae hyun

    park jae hyun Member Licensed 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.
     
  2. Erel

    Erel Administrator Staff Member Licensed User

    Please use [code]code here...[/code] tags when posting code.
     
  3. park jae hyun

    park jae hyun Member Licensed User

    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(
    3006003202520Colors.Transparent , False6True
    End Sub


    Sub button2_click
    DrawCircleArc(
    3006003202520Colors.Green, False6True)
    End Sub
    question
    Not transparent.
     
  4. Erel

    Erel Administrator Staff Member Licensed User

    It is very simple to draw arcs with XUI library.

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

    [​IMG]

    Code:
    Sub Activity_Create(FirstTime As Boolean)
       
    Dim c As B4XCanvas
       c.Initialize(
    Activity)
       
    Dim p As B4XPath
       p.InitializeArc(
    50%x50%y100dip0135)
       c.DrawPath(p, 
    0xffff0000True0)
       p.InitializeArc(
    50%x50%y100dip90135)
       c.DrawPath(p, 
    0x8800ff00True0)
       c.Invalidate
       c.Release
    End Sub
     
  5. park jae hyun

    park jae hyun Member Licensed User

    Thank you for answer.
    But I think I got the wrong question.
    tttset.jpg
    I want to clear a specific part.
     
  6. klaus

    klaus Expert Licensed 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..
     
  7. Erel

    Erel Administrator Staff Member Licensed User

    Simple:

    [​IMG]

    Code:
    Dim c As B4XCanvas
    c.Initialize(
    Activity)
    Dim p As B4XPath
    p.InitializeArc(
    50%x50%y100dip0135)
    c.DrawPath(p, 
    0xffff0000True0)
    p.InitializeArc(
    55%x55%y40dip0135)
    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.
     
  8. park jae hyun

    park jae hyun Member Licensed User

    klaus , Erel
    Thank you very much.
    Thank you very much.
     
Loading...
  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