Android Question [Solved] BitmapWrapper vs android.graphics.Bitmap

Johan Schoeman

Expert
Licensed User
Longtime User
I have this code in my B4A project:

B4X:
    countries1 = Array As String(" Brazil ", " Canada ", " France ", " Gremany ", " USA ")
    Dim mbm(5) As Bitmap
    mbm(0).Initialize(File.DirAssets,"brazil.png")
    mbm(1).Initialize(File.DirAssets,"canada.png")
    mbm(2).Initialize(File.DirAssets,"france.png")   
    mbm(3).Initialize(File.DirAssets,"germany.png")   
    mbm(4).Initialize(File.DirAssets,"usa.png")   
    vsw4.ImageFromBitmap = True
    vsw4.ImageBitmaps = mbm

In a wrapper I have this:

B4X:
    private Bitmap[] bImage = null;
    public void setImageBitmaps(Bitmap[] bImage) {
        this.bImage = bImage;
    }

When I try to compile the B4A project it generates this error:

B4A version: 5.50
Parsing code. (0.00s)
Compiling code. (0.06s)
Compiling layouts code. (0.00s)
Generating R file. (0.07s)
Compiling generated Java code. Error
B4A line: 84
vsw4.ImageBitmaps = mbm
javac 1.8.0_66
src\JHS\AndroidSpinnerWheel\main.java:413: error: incompatible types: BitmapWrapper[] cannot be converted to Bitmap[]
mostCurrent._vsw4.setImageBitmaps((android.graphics.Bitmap[])(_mbm));
^


Have also tried to change the B4A code to the below where I try to pass it as an Object:

B4X:
    countries1 = Array As String(" Brazil ", " Canada ", " France ", " Gremany ", " USA ")
    Dim mbm(5) As Bitmap
    mbm(0).Initialize(File.DirAssets,"brazil.png")
    mbm(1).Initialize(File.DirAssets,"canada.png")
    mbm(2).Initialize(File.DirAssets,"france.png")   
    mbm(3).Initialize(File.DirAssets,"germany.png")   
    mbm(4).Initialize(File.DirAssets,"usa.png")   
    Dim aa As Object = mbm
    vsw4.ImageFromBitmap = True
    vsw4.ImageBitmaps = aa

This compiles but once the app starts it generates the following error:

** Service (starter) Create **
** Service (starter) Start **
** Activity (main) Create, isFirst = true **
main_activity_create (java line: 416)
java.lang.ClassCastException: anywheresoftware.b4a.objects.drawable.CanvasWrapper$BitmapWrapper[] cannot be cast to android.graphics.Bitmap[]
at JHS.AndroidSpinnerWheel.main._activity_create(main.java:416)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at anywheresoftware.b4a.BA.raiseEvent2(BA.java:169)
at JHS.AndroidSpinnerWheel.main.afterFirstLayout(main.java:102)
at JHS.AndroidSpinnerWheel.main.access$000(main.java:17)
at JHS.AndroidSpinnerWheel.main$WaitForLayout.run(main.java:80)
at android.os.Handler.handleCallback(Handler.java:605)
at android.os.Handler.dispatchMessage(Handler.java:92)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:4514)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:790)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:557)
at dalvik.system.NativeStart.main(Native Method)
java.lang.ClassCastException: anywheresoftware.b4a.objects.drawable.CanvasWrapper$BitmapWrapper[] cannot be cast to android.graphics.Bitmap[]
** Activity (main) Resume **

The question is how do I convert the B4A BitmapWrapper object to an android.graphics.Bitmap object inside the wrapper?

In the wrapper I need to set and ImageView's bitmap i.e
B4X:
img.setImageBitmap(bImage[index]);
 
Cookies are required to use this site. You must accept them to continue using the site. Learn more…