Android Question BitmapCreatorEffects DrawThroughMask issue

Martin D.

Active Member
Licensed User
B4X:
    Dim view As B4XView = xui.CreatePanel("")
    Root1.AddView(view, 0, 0, 50%x, 50%x)

    Dim mask As B4XBitmap = LoadBitmapResize(File.DirAssets, "mask.png", view.Width, view.Height, False)
   
    Dim bc As BitmapCreator
    bc.Initialize(view.Width, view.Height)
    bc.FillRadialGradient(Array As Int(xui.Color_Black, xui.Color_Gray, xui.Color_Black), bc.TargetRect)
   
    Dim gradient As B4XBitmap = bc.bitmap
    gradient = gradient.Resize(gradient.Width, gradient.Height, False)

    Dim bce As BitmapCreatorEffects
    bce.Initialize
   
    view.SetBitmap(bce.DrawThroughMask(gradient, mask))

If you comment line 11, app crashes, even despite no effective resize.
 

Martin D.

Active Member
Licensed User
bitmapcreatoreffects_drawthroughmask (java line: 497)
java.lang.ArrayIndexOutOfBoundsException: length=129600; index=129603
at b4a.example.bitmapcreator._istransparent(bitmapcreator.java:4770)
at MD.Test.bitmapcreatoreffects._drawthroughmask(bitmapcreatoreffects.java:497)
at MD.Test.b4xmainpage._b4xpage_created(b4xmainpage.java:63)
at MD.Test.b4xmainpage.callSub(b4xmainpage.java:85)
at anywheresoftware.b4a.keywords.Common.CallSub4(Common.java:1069)
at anywheresoftware.b4a.keywords.Common.CallSubNew2(Common.java:1040)
at MD.Test.b4xpagesmanager._createpageifneeded(b4xpagesmanager.java:529)
at MD.Test.b4xpagesmanager._showpage(b4xpagesmanager.java:866)
at MD.Test.b4xpagesmanager._addpage(b4xpagesmanager.java:200)
at MD.Test.b4xpagesmanager._addpageandcreate(b4xpagesmanager.java:207)
at MD.Test.b4xpagesmanager._initialize(b4xpagesmanager.java:717)
at MD.Test.main._activity_create(main.java:366)
at java.lang.reflect.Method.invoke(Native Method)
at anywheresoftware.b4a.BA.raiseEvent2(BA.java:213)
at MD.Test.main.afterFirstLayout(main.java:105)
at MD.Test.main.access$000(main.java:17)
at MD.Test.main$WaitForLayout.run(main.java:83)
at android.os.Handler.handleCallback(Handler.java:938)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loopOnce(Looper.java:226)
at android.os.Looper.loop(Looper.java:313)
at android.app.ActivityThread.main(ActivityThread.java:8751)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:571)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1135)
java.lang.ArrayIndexOutOfBoundsException: length=129600; index=129603

Important : no problem when running on an AVD (Android SDK 32). However I do get this error message on my Galaxy S22. Also, I replaced the gradient method with FillRect and I got same error message.
 
Last edited:
Upvote 0

kimstudio

Active Member
Licensed User
Longtime User
The width and height of mask must be = or > gradient's, so Log width and height of both gradient and mask before DrawThroughMask may help to target the problem.
 
Upvote 0

Martin D.

Active Member
Licensed User
Width and Height were the same but like Erel said, scale was different.

BitmapCreator returns a bitmap of scale 1.
Resizing any bitmap scales it to the device (3 in my case) so it's tricky if you use LoadBitmap instead LoadBitmapResize -- You generally resize everything, so you end up with scales of 3 and BC Bitmaps with scale of 1.
 
Last edited:
Upvote 0
Top