Android Question CreateBitmapWithAlpha with android 8.1 (SOLVED)

BeneBarros

Active Member
Licensed User
Longtime User
My Samsung J7 Neo phone updated the android to 8.1.
Now the "CreateBitmapWithAlpha" routine does not work right. It's locking.
Can someone help me?
B4X:
Private Sub CreateBitmapWithAlpha(myOriginalBitmap As Bitmap, newAlpha As Int) As Bitmap
  Dim canvas1 As Canvas
  Dim myNewBitmap As Bitmap
  myNewBitmap.initializeMutable(myOriginalBitmap.Width,myOriginalBitmap.Height)
  canvas1.initialize2(myNewBitmap)
  Dim CanvJO As JavaObject = canvas1
  CanvJO = CanvJO.GetField("canvas") 
  Dim J As JavaObject
  J.initializeContext()
  J.Runmethod("alphatize",Array(CanvJO, myOriginalBitmap, newAlpha))
  Return(myNewBitmap)
End Sub
 

Peter Simpson

Expert
Licensed User
Longtime User
Have you tried in debug mode to single step through each line of code until the code hangs for a while, you can see exactly where it hangs then?

Are you sure that it's hanging in the CreateBitmapWithAlpha sub?

You could also try using
B4X:
Try
   
Catch
    Log(LastException)
End Try
 
Upvote 0

JordiCP

Expert
Licensed User
Longtime User
Tested. If you add some measurements to your code you will find that the time is not lost in "CreateBitmapWithalpha", but on "DrawFirework"
Modify your TimeR_Tick routine

B4X:
Private Sub Timer_Tick
    Dim t0 As Long = DateTime.now    '<--- Added
    For fIdx = 0  To nFires - 1
        DrawFireWork(fIdx) 
    Next
    Dim t1 As Long =DateTime.now
    Dim bmp As Bitmap = CreateBitmapWithAlpha(ivFireW.Bitmap, 245) 

    Dim tFinal As Long = DateTime.now     '<--- Added   
    Log("DrawFirework took "&(t1-t0)&"msec.  CreateBitmapWithAlpha took:"&(tFinal -t1)&"msec")   '<--- Added

    ivFireW.Bitmap = bmp
    gv.Invalidate
End Sub

When the fires start, the logs say
B4X:
...
DrawFirework took 0msec.  CreateBitmapWithAlpha took:6msec
DrawFirework took 0msec.  CreateBitmapWithAlpha took:6msec
DrawFirework took 0msec.  CreateBitmapWithAlpha took:6msec
...

But after some time, perhaps when the fireworks do Booommmmm!!!!!, these are the logs

B4X:
...
DrawFirework took 33msec.  CreateBitmapWithAlpha took:5msec
DrawFirework took 288msec.  CreateBitmapWithAlpha took:6msec
DrawFirework took 281msec.  CreateBitmapWithAlpha took:5msec
DrawFirework took 567msec.  CreateBitmapWithAlpha took:7msec
DrawFirework took 571msec.  CreateBitmapWithAlpha took:5msec
DrawFirework took 599msec.  CreateBitmapWithAlpha took:6msec
... 
...(and increasing)
 
Upvote 0

BeneBarros

Active Member
Licensed User
Longtime User
Very strange.
The problem is happening in Canvas.DrawBitmap

If lines 107 and 117 have been replaced

from
cvs.DrawBitmap (imgSparks, RtSrc, RtDest)

to
cvs.DrawCircle (nFW.X, nFW.Y, 1, Colors.White, True, 0)


it works perfectly
 
Upvote 0

BeneBarros

Active Member
Licensed User
Longtime User
I haven't tried your project. Make sure that imgSparks is not too large. The smaller it will be the faster the drawing will be.
hi Erel,
Image sparks is small, 300x300px.
Application runs on all versions of android, except on 8.1.
The problem only happens in Canvas.DrawBitmap ().
If I change to Canvas.DrawCircle () it works perfectly.
 
Upvote 0

BeneBarros

Active Member
Licensed User
Longtime User
hi Erel,
Image sparks is small, 300x300px.
Application runs on all versions of android, except on 8.1.
The problem only happens in Canvas.DrawBitmap ().
If I change to Canvas.DrawCircle () it works perfectly.
Ok, Erel, you're right. decreasing the image size improves performance.

Is this a problem with version 8.1?
 
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…