Private Sub HandeChooserResult (ChooserResult As MediaChooserResult)
For Each v As B4XView In Root.GetAllViewsRecursive
If v.Tag Is B4XImageView Then v.Tag.As(B4XImageView).Clear
Next
If ChooserResult.Success = False Then Return
Dim bmp As B4XBitmap = xui.LoadBitmap(ChooserResult.MediaDir, ChooserResult.MediaFile)
If bmp.Width > 2000 Or bmp.Height > 2000 Then bmp = bmp.Resize(2000, 2000, True)
#if B4A
If ChooserResult.Mime = "image/jpeg" Then
bmp = RotateJpegs(ChooserResult, bmp)
End If
#end if
ivOrigSmall.Bitmap = bmp
ivOriginal.mBackgroundColor = xui.Color_Transparent
Wait For (SelfieSegmenter.Process(bmp)) Complete (res As SelfieSegmentationResult)
If res.Success Then
Dim AfterMask As B4XBitmap = RemoveMask(bmp, res.ForegroundBitmap)
ivOriginal.Bitmap = AfterMask
ivMaskSmall.Bitmap = res.ForegroundBitmap
End If
End Sub
Private Sub RemoveMask(Selfie As B4XBitmap, Mask As B4XBitmap) As B4XBitmap
Dim SelfieBC As BitmapCreator = CreateBC(Selfie)
Dim MaskBC As BitmapCreator = CreateBC(Mask)
Dim oldargb, newargb, a As ARGBColor
SelfieBC.ColorToARGB(xui.Color_Black, oldargb)
SelfieBC.ColorToARGB(xui.Color_Transparent, newargb)
For x = 0 To SelfieBC.mWidth - 1
For y = 0 To SelfieBC.mHeight - 1
MaskBC.GetARGB(x, y, a)
If a.r = oldargb.r And a.g = oldargb.g And a.b = oldargb.b Then
SelfieBC.SetARGB(x, y, newargb)
End If
Next
Next
Return SelfieBC.Bitmap
End Sub