B4J Question How can one clear a clipped path of a canvas

Discussion in 'B4J Questions' started by VB6Back, Jun 10, 2015.

  1. VB6Back

    VB6Back Member

    Hi All,

    I am wondering if there is a way to clear the content of a clipped region in a canvas?

    I tried the obvious but that didn't work.

    Code:
    Sub ClearRegoin(cnvs As Canvas,Region As List)
       
        cnvs.ClipPath(Region)
        cnvs.ClearRect(
    0,0,cnvs.Width,cnvs.Height)
        cnvs.RemoveClip
       
    End Sub
    In another post Erel states that we can use DrawRect to clear: http://www.b4x.com/android/forum/posts/284787/

    Any idea on how this could be done?
     
  2. Erel

    Erel Administrator Staff Member Licensed User

    Try:
    Code:
    cnvs.DrawRect(00, cnvs.Width, cnvs.Height, fx.Colors.Transparent, True0)
     
  3. VB6Back

    VB6Back Member

    Thanks Erel for your reply.

    I tried the above but nothing is cleared from the canvas. If I use a non transparent color the clipped region is painted as expected.

    Any other suggestion?
     
  4. Erel

    Erel Administrator Staff Member Licensed User

    I see it too. It seems like ClearRect doesn't work properly with the clipped regions.
    The workaround will be to paint the background to the canvas instead.
     
  5. VB6Back

    VB6Back Member

    I tried the following with no effect:

    Code:
    Sub ClearRegoin(cnvs As Canvas,Region As List)
       
        cnvs.ClipPath(Region)
    '    cnvs.ClearRect(0,0,cnvs.Width,cnvs.Height)

        
    Dim p As Paint = fx.Colors.Transparent
        cnvs.DrawRect(
    0,0,cnvs.Width,cnvs.Height,p,True,1)

        cnvs.RemoveClip
       
    End Sub
     
  6. Erel

    Erel Administrator Staff Member Licensed User

    It will not work as drawing a transparent color does nothing. As I wrote above you need to paint the background to the canvas.
     
Loading...