Android Question Snapshot with SimpleMediaManager are not displayed

angel_

Well-Known Member
Licensed User
Longtime User
When taking a Snapshot of the screen, images loaded with SimpleMediaManager are not displayed on the image.

B4X:
Private Sub B4XPage_Created (Root1 As B4XView)
    Root = Root1
    Root.LoadLayout("MainPage")
    
    MediaManager.Initialize
End Sub

Private Sub Button1_Click
    MediaManager.SetMediaFromFile(Panel1, File.DirAssets, "img.png", "image/*", Null)
    
    ScreenShoot
End Sub

Private Sub ScreenShoot
    Dim bmp As B4XBitmap
    Dim Screen As String = "Screen"
    
    bmp = Panel2.Snapshot
    
    B4XImageView1.Clear
    B4XImageView1.Update
    
    Dim Out As OutputStream
    Out = File.OpenOutput(xui.DefaultFolder, Screen & ".PNG", False)
    bmp.WriteToStream(Out, 100, "PNG")
    Out.Close  
    
    B4XImageView1.Load(xui.DefaultFolder, Screen & ".PNG")
    B4XImageView1.Update
End Sub
 

Attachments

  • SnapShot.zip
    19.8 KB · Views: 129
Solution
With the latest version, you can do it like this:
B4X:
Private Sub B4XPage_Created (Root1 As B4XView)
    Root = Root1
    Root.LoadLayout("MainPage")
    MediaManager.Initialize
End Sub

Private Sub Button1_Click
    MediaManager.SetMediaFromFile(Panel1, File.DirAssets, "img.png", "image/*", CreateMap(MediaManager.REQUEST_CALLBACK: Me))
   Wait For (target) SMM_MediaReady (Success As Boolean, Media As SMMedia)
    ScreenShoot
End Sub

Private Sub ScreenShoot
    Dim bmp As B4XBitmap = Panel2.Snapshot
   'You can also save the image as you did, however it is not necessary.
    B4XImageView1.Bitmap = bmp
End Sub
No need to disable the fade animation nor to use Sleep.

Erel

B4X founder
Staff member
Licensed User
Longtime User
Correct way to create a zip file from a B4XPages project:
B4X:
'Ctrl + click to export as zip: ide://run?File=%B4X%\Zipper.jar&Args=Project.zip

There are two things here:
1. Images are displayed with a fade-in animation. You should disable it.
2. Images are loaded asynchronously (to avoid impacting the main thread).

This code will work:
B4X:
Private Sub B4XPage_Created (Root1 As B4XView)
    Root = Root1
    Root.LoadLayout("MainPage")
    MediaManager.Initialize
    MediaManager.DefaultFadeAnimationDuration = 0 '<----
End Sub

Private Sub Button1_Click
    MediaManager.SetMediaFromFile(Panel1, File.DirAssets, "img.png", "image/*", Null)
    Sleep(100) '<---
    ScreenShoot
End Sub

Private Sub ScreenShoot
    Dim bmp As B4XBitmap = Panel2.Snapshot
   'You can also save the image as you did, however it is not necessary.
    B4XImageView1.Bitmap = bmp
End Sub

I plan to add a "Ready" event to SMM.
 
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
With the latest version, you can do it like this:
B4X:
Private Sub B4XPage_Created (Root1 As B4XView)
    Root = Root1
    Root.LoadLayout("MainPage")
    MediaManager.Initialize
End Sub

Private Sub Button1_Click
    MediaManager.SetMediaFromFile(Panel1, File.DirAssets, "img.png", "image/*", CreateMap(MediaManager.REQUEST_CALLBACK: Me))
   Wait For (target) SMM_MediaReady (Success As Boolean, Media As SMMedia)
    ScreenShoot
End Sub

Private Sub ScreenShoot
    Dim bmp As B4XBitmap = Panel2.Snapshot
   'You can also save the image as you did, however it is not necessary.
    B4XImageView1.Bitmap = bmp
End Sub
No need to disable the fade animation nor to use Sleep.
 
Upvote 1
Solution
Top