Why does this assignment cause an error: java.lang.RuntimeException: Object should first be initialized (B4XBitmap).
even though Crop returns an object of type B4XBitmap?
And how to get around this problem?
B4X:
Dim xBmp As B4XBitmap = B4XImageView1.Bitmap.Crop(Left, Top, Width, Height)
Actually the log of the code below writes "Not initialized" but mine is a simple test, only two B4XImageView and I immediately see the image of B4XImageView1; on click... that exception.
B4X:
If Not(B4XImageView1.Bitmap.IsInitialized) Then
Log("Not initialized")
Else
Log("Initialized")
End If
Very simple code:
Private Sub Button1_Click
Dim Left, Top, Width, Height As Int
Left = B4XImageView1.mBase.Width / 3
Top = B4XImageView1.mBase.Height/ 3
Width = 100dip
Height = 40dip
If Not(B4XImageView1.Bitmap.IsInitialized) Then
Log("Not initialized")
Else
Log("Initialized")
End If
Dim xBmp As B4XBitmap = B4XImageView1.Bitmap.Crop(Left, Top, Width, Height)
B4XImageView2.Bitmap = xBmp
End Sub
You are not setting B4XImageView1 bitmap. You are replacing the drawable of the base view (B4XImageView1.mBase) with a bitmap drawable. Don't do it.
You should instead set the bitmap programmatically.