Sub viewAsBitmap (aView As View) As Bitmap
Dim b As Bitmap
Dim c As Canvas
b.InitializeMutable(aView.Width, aView.Height) ' Initialize mutable bitmap to contain size of aView ...
c.Initialize2(b) ' Get bitmap canvas ...
' Get B4A.Canvas android.graphics.Canvas (Android native type) field
' We need it as native Android type in order to call the "draw" function below ...
Dim args(1) As Object
Dim types(1) As String
Dim r As Reflector
r.Target = c
args(0) = r.GetField("canvas") ' Get android.graphics.Canvas field ...
types(0) = "android.graphics.Canvas"
' Draw aView content onto the bitmap canvas ...
r.Target = aView
r.RunMethod4("draw", args, types)
Return b
End Sub