Android Question Get Bitmap from all B4XPages

Blueforcer

Well-Known Member
Licensed User
Longtime User
i build all my dynamic pages with B4XPages.AddPageAndCreate

after that i want to get the bitmap of all pages. I tried it with

B4X:
ListOfPageIDs=B4XPages.GetManager.mStackOfPageIds.AsList
For Each pageID As String In ListOfPageIDs
    PageBitmaps.Add(B4XPages.GetManager.FindPIFromB4XPage(B4XPages.GetPage(pageID)).Root.GetBitmap)
Next

But mStackOfPageIds only gives me the ID from pages wich i had opened at least once.
How i can get the bitmap from all pages without to show them before?
 
Last edited:

Blueforcer

Well-Known Member
Licensed User
Longtime User
Just found out that you cannot get an bitmap from B4XPage root before shown once, even it is created:

B4X:
Private Sub B4XPage_Created (Root1 As B4XView)
    Root = Root1
    PlaceViews
    mybitmap=Root.GetBitmap
End Sub

java.lang.RuntimeException: Object should first be initialized (B4XBitmap).


i also tried to get a bitmap via canvas, but the image is complete black but hast its correct size.
B4X:
    Dim out As OutputStream
    out = File.OpenOutput(System.AppFolder, "Test.jpg", False)
    Functions.viewAsBitmap(Root).WriteToStream(out, 100, "JPEG")
    out.Close

Sub viewAsBitmap (aView As View) As Bitmap
    Dim b As Bitmap
    Dim c As Canvas
    b.InitializeMutable(aView.Width, aView.Height) ' Initialize mutable bitmap to contain size of aView ...
    c.Initialize2(b) ' Get bitmap canvas ...
    ' Get B4A.Canvas android.graphics.Canvas (Android native type) field
    ' We need it as native Android type in order to call the "draw" function below ...
    Dim args(1) As Object
    Dim types(1) As String
    Dim r As Reflector
    r.Target = c
    args(0) = r.GetField("canvas") ' Get android.graphics.Canvas field ...
    types(0) = "android.graphics.Canvas"
    ' Draw aView content onto the bitmap canvas ...
    r.Target = aView
    r.RunMethod4("draw", args, types)
    Return b
End Sub


Any chance to get my goal?
 
Last edited:
Upvote 0
Top