Panel1.SetBitmap(CreateRoundBitmap(xui.LoadBitmap(File.DirAssets, "random-dice.jpg"), Panel1.Height))
B4XImageView2.ResizeMode = "FIT"
B4XImageView2.RoundedImage = True
B4XImageView2.Load(File.DirAssets, "random-dice.jpg")
Sub TakeScreenshot As Bitmap
Dim jo As JavaObject
jo.InitializeContext
Dim decor As JavaObject = jo.RunMethodJO("getWindow", Null).RunMethod("getDecorView", Null)
Dim decorChild As JavaObject = decor.RunMethod("getChildAt", Array(0))
decorChild.RunMethod("setDrawingCacheEnabled", Array(True))
decorChild.RunMethod("buildDrawingCache", Null)
Dim bmp As Bitmap = decorChild.RunMethod("getDrawingCache", Array(True))
bmp.Initialize3(bmp)
decorChild.RunMethod("setDrawingCacheEnabled", Array(False))
Return bmp
End Sub
'xui is a global XUI variable.
Sub CreateRoundBitmap (Input As B4XBitmap, Size As Int) As B4XBitmap
If Input.Width <> Input.Height Then
'if the image is not square then we crop it to be a square.
Dim l As Int = Min(Input.Width, Input.Height)
Input = Input.Crop(Input.Width / 2 - l / 2, Input.Height / 2 - l / 2, l, l)
End If
Dim c As B4XCanvas
Dim xview As B4XView = xui.CreatePanel("")
xview.SetLayoutAnimated(0, 0, 0, Size, Size)
c.Initialize(xview)
Dim path As B4XPath
path.InitializeOval(c.TargetRect)
c.ClipPath(path)
c.DrawBitmap(Input.Resize(Size, Size, False), c.TargetRect)
c.RemoveClip
c.DrawCircle(c.TargetRect.CenterX, c.TargetRect.CenterY, c.TargetRect.Width / 2 - 2dip, xui.Color_Transparent, False, 0dip) 'comment this line to remove the border
c.Invalidate
Dim res As B4XBitmap = c.CreateBitmap
c.Release
Return res
End Sub