Public Sub drawMask
Dim p As B4XView = xui.CreatePanel("")
p.SetLayoutAnimated(0, 0, 0, B4XImageView1.mBase.Width, B4XImageView1.mBase.Height)
Dim cnv As B4XCanvas
cnv.Initialize(p)
cnv.DrawPath(makeMask(p), xui.Color_Red, True, 0)
Dim MaskBmp As B4XBitmap = cnv.CreateBitmap
cnv.Invalidate
cnv.Release
B4XImageView1.mBackgroundColor = xui.Color_Transparent
B4XImageView1.ResizeMode = "FILL"
B4XImageView1.Update
Dim ImageBmp As B4XBitmap = xui.LoadBitmapResize(File.DirAssets, "1.png", MaskBmp.Width, MaskBmp.Height, False)
Dim BitmapCreatorEffects1 As BitmapCreatorEffects
BitmapCreatorEffects1.Initialize
B4XImageView1.Bitmap = BitmapCreatorEffects1.DrawThroughMask(ImageBmp, MaskBmp)
End Sub
Private Sub makeMask(target As B4XView) As B4XPath
Dim a As Float = target.Height / 2
Dim b As Float = target.Width / 3
Dim r As Float = (a * a + b * b) / (b + b)
Dim angle As Float = ASin(a / r)
Dim d As Float = angle / 20
Dim p As B4XPath
p.Initialize(b + b, 0)
For i = 1 To 40
angle = angle - d
p.LineTo(3 * b - r + r * Cos(angle), a - r * Sin(angle))
Next
p.LineTo(0, a + a)
p.LineTo(0, 0)
Return p
End Sub