Android Question Snapshot with multiple images with SimpleMediaManager

angel_

Well-Known Member
Licensed User
Longtime User
I'm trying to capture an image loaded with multiple views loaded with SimpleMediaManager but I can't get all the images to display. I've tried adding a sleep but it doesn't work either.

B4X:
Private Sub Button1_Click
    pnlSnapshot.Color = xui.Color_Cyan
   
    If pnl1.NumberOfViews > 0 Then pnl1.RemoveAllViews
    If pnl2.NumberOfViews > 0 Then pnl2.RemoveAllViews
    If pnl3.NumberOfViews > 0 Then pnl3.RemoveAllViews
    If pnl4.NumberOfViews > 0 Then pnl4.RemoveAllViews
   
    LoadImages

    Sleep(300)
   
    pnlSnapshot.SetBitmap(pnlImages.Snapshot)
End Sub

Private Sub LoadImages
    Dim ListPanels As List = Array As B4XView(pnl1, pnl2, pnl3, pnl4)
   
    For Each pnl As B4XView In ListPanels
        MediaManager.SetMediaFromFile(pnl, File.DirAssets, "img.png", "image/*", CreateMap(MediaManager.REQUEST_BACKGROUND: xui.Color_Transparent, MediaManager.REQUEST_CALLBACK: Me))
        Wait For (pnl) SMM_MediaReady (Success As Boolean, Media As SMMedia)
    Next
End Sub
 

Attachments

  • Project.zip
    32.5 KB · Views: 106

josejad

Expert
Licensed User
Longtime User
Hi Angel:

Based on this sample, try this

B4X:
Private Sub Button1_Click
    pnlSnapshot.Color = xui.Color_Cyan
  
    If pnl1.NumberOfViews > 0 Then pnl1.RemoveAllViews
    If pnl2.NumberOfViews > 0 Then pnl2.RemoveAllViews
    If pnl3.NumberOfViews > 0 Then pnl3.RemoveAllViews
    If pnl4.NumberOfViews > 0 Then pnl4.RemoveAllViews
  
    LoadImages
    wait for LoadImages_Complete 'Added line
    pnlSnapshot.SetBitmap(pnlImages.Snapshot)
End Sub

Private Sub LoadImages
    Dim ListPanels As List = Array As B4XView(pnl1, pnl2, pnl3, pnl4)
  
    For Each pnl As B4XView In ListPanels
        MediaManager.SetMediaFromFile(pnl, File.DirAssets, "img.png", "image/*", CreateMap(MediaManager.REQUEST_BACKGROUND: xui.Color_Transparent, MediaManager.REQUEST_CALLBACK: Me))
        Wait For (pnl) SMM_MediaReady (Success As Boolean, Media As SMMedia)
    Next
    CallSubDelayed(Me, "LoadImages_Complete") 'Added line
End Sub

1650348818220.png
 
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
First step is to properly wait for the images to be loaded.

This is better than using CallSubDelayed.
 
Upvote 0

josejad

Expert
Licensed User
Longtime User
This is better than using CallSubDelayed.

Ah, ok¡¡

Then, it should be something like:

B4X:
Private Sub Button1_Click
    pnlSnapshot.Color = xui.Color_Cyan
    
    If pnl1.NumberOfViews > 0 Then pnl1.RemoveAllViews
    If pnl2.NumberOfViews > 0 Then pnl2.RemoveAllViews
    If pnl3.NumberOfViews > 0 Then pnl3.RemoveAllViews
    If pnl4.NumberOfViews > 0 Then pnl4.RemoveAllViews
    
    Wait For(LoadImages) Complete (Success As Boolean)
    
    If Success Then
        pnlSnapshot.SetBitmap(pnlImages.Snapshot)
    Else
        xui.MsgboxAsync("There was an error loading the bitmaps", "Error")
    End If
    
End Sub

Private Sub LoadImages As ResumableSub
    Dim SuccessImage As Boolean = True
    Dim ListPanels As List = Array As B4XView(pnl1, pnl2, pnl3, pnl4)
    
    For Each pnl As B4XView In ListPanels
        MediaManager.SetMediaFromFile(pnl, File.DirAssets, "img.png", "image/*", CreateMap(MediaManager.REQUEST_BACKGROUND: xui.Color_Transparent, MediaManager.REQUEST_CALLBACK: Me))
        Wait For (pnl) SMM_MediaReady (Success As Boolean, Media As SMMedia)
        SuccessImage = SuccessImage And Success
    Next
    Return SuccessImage
End Sub
 
Upvote 0
Top