Android Question Cut out shapes from canvas

Yvon Steinthal

Active Member
Licensed User
Longtime User
Hello,

Im looking for a way to cutout a circle from a canvas.

What im doing exacly is generating in a canvas, red and green dots to simulate 3D (visual test) with red/green glasses. And i'd like to cut out different shapes from that square canvas (triangle, diamond, circle...) and having the outside of that shape Transparent!

Any clues as to how to do just that?

Y.
 

Yvon Steinthal

Active Member
Licensed User
Longtime User
Thanks Erel, i have found this solution a bit before you wrote yours:
The two methods are not mine, took them from one of your old answers.
Looking for the fastest way, but it works well enough.

B4X:
Dim circle As Path
   circle.Initialize(ImageSize/2, ImageSize/2)
   
   Dim radius As Float = ImageSize/2
   PathAddCircle(circle, ImageSize/2, ImageSize/2, radius)
   Dim fullScreen As Path
   fullScreen.Initialize(0, 0)
   fullScreen.LineTo(ImageSize, 0)
   fullScreen.LineTo(ImageSize, ImageSize)
   fullScreen.LineTo(0, ImageSize)
   Dim p As Path = OpPath(fullScreen, circle, "DIFFERENCE")
   cvsCircle.ClipPath(p)
   
   Dim dest As Rect
   dest.Initialize(0, 0, ImageSize, ImageSize)
   cvsCircle.DrawColor(Colors.Transparent)

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
Cookies are required to use this site. You must accept them to continue using the site. Learn more…