Android Question B4XBitmap assignment

LucaMs

Expert
Licensed User
Longtime User
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)
 

LucaMs

Expert
Licensed User
Longtime User
I tried and I have no problems.

I am getting the error when B4XImageView has no image assigned

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
 
Upvote 0
Top