Android Question B4XView - SetBitmap - B4XBitmap

Mahares

Well Known Member
Licensed User
f I have a B4XView, its SetBitmap property (method) should require a B4XBitmap
You can still use B4XBitmap:
B4X:
Private ImageView1 As B4XView
Dim b As B4XBitmap=LoadBitmapResize(File.DirAssets,"hannibal.jpg", 50dip, 50dip, True)  'resizes the image
    ImageView1.setbitmap(b)
B4X:
Private ImageView1 As ImageView
Dim b As Bitmap=LoadBitmapResize(File.DirAssets,"hannibal.jpg", 50dip, 50dip, True)  'fits the image
    ImageView1.Bitmap = b
 

LucaMs

Expert
Licensed User
You can still use B4XBitmap:
B4X:
Private ImageView1 As B4XView
Dim b As B4XBitmap=LoadBitmapResize(File.DirAssets,"hannibal.jpg", 50dip, 50dip, True) 'resizes the image
ImageView1.setbitmap(b)
Although it was not clearly explained in the contextual help, I had tried and got an error. I hadn't read the error message right and thought the "empirical" attempt failed because of the type.
Instead, the problem was a null object returned by:
B4X:
Dim xBmp As B4XBitmap = xLbl.GetBitmap
where xLbl is a B4XView "containing" a B4A Label.
Using xLbl.Snapshot solved the problem.


However, I still think that B4XView.SetBitmap should require a B4XBitmap (and the contextual help should be modified anyway).
 

LucaMs

Expert
Licensed User
There is a technical nuance here. The method accepts the native unwrapped type which is android.graphics.Bitmap. Any wrapper of android.graphics.Bitmap will work, including Bitmap and B4XBitmap.
Yes, now I understand why it is a method and not a property.
Anyway, it's worth writing it in contextual help.
 
Top