Android Question Is there a way to invert a clip path?

NeoTechni

Well-Known Member
Licensed User
Longtime User
Let's say I've used the advanced graphics library to make a circle clip path, is there a way to select only the outside of the clip path? (Without generating the opposite clip path manually from the outside in)
 

NeoTechni

Well-Known Member
Licensed User
Longtime User
The ABExtDrawing library lets you make circle paths for example

but what is the native API call?
I only know of Canvas.ClipPath and Canvas.RemoveClip
 
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User


B4X:
Sub Activity_Create(FirstTime As Boolean)
   Dim cvs As Canvas
   cvs.Initialize(Activity)
   Dim circle As Path
   circle.Initialize(50%x, 50%y)
   Dim radius As Float = 100dip
   PathAddCircle(circle, 50%x, 50%y, radius)
   Dim fullScreen As Path
   fullScreen.Initialize(0, 0)
   fullScreen.LineTo(100%x, 0)
   fullScreen.LineTo(100%x, 100%y)
   fullScreen.LineTo(0, 100%y)
   Dim p As Path = OpPath(fullScreen, circle, "DIFFERENCE")
   cvs.ClipPath(p)
   
   Dim dest As Rect
   dest.Initialize(0, 0, 100%x, 100%y)
   cvs.DrawBitmap(LoadBitmap(File.DirAssets, "b4a.png"), Null, dest)
End Sub

Sub OpPath(p1 As Path, p2 As Path, Op As String) As Path
   Dim jo As JavaObject = p1
   Dim success As Boolean = jo.RunMethod("op", Array(p2, Op))
   Log($"Success: ${success}"$)
   Return p1   
End Sub

Sub PathAddCircle(path As Path, x As Float, y As Float, radius As Float)
  Dim jo As JavaObject = path
  jo.RunMethod("addCircle", Array(x, y, radius, "CW"))
End Sub
 
Upvote 0

NeoTechni

Well-Known Member
Licensed User
Longtime User
That's awesome! Thank you.

For anyone else who finds this, I found the other operations OpPath would accept

Path.Op
DIFFERENCE
Subtract the second path from the first path.

Path.Op INTERSECT
Intersect the two paths.

Path.Op REVERSE_DIFFERENCE
Subtract the first path from the second path.

Path.Op UNION
Union (inclusive-or) the two paths.

Path.Op XOR
Exclusive-or the two paths.
 
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…