Screenshot program is too slow

NeoTechni

Well-Known Member
Licensed User
Longtime User
Now it's not the devs fault, the one in the Android SDK is too slow as well

At some point, you must:

B4X:
dim bg as canvas
bg.Initialize(activity)

B4X:
Sub UniqueFilename(Dir As String, Filename As String, Append As String ) as string
   Dim temp As Int ,Lindex As Int, Lpart As String , Rpart As String 
   If Append.Length=0 Then Append=" (#)"
   If File.Exists(Dir, Filename) Then
      Lindex= filename.LastIndexOf(".")
      If Lindex=-1 Then
         Lpart=filename
      Else
         lpart = filename.SubString2(0,lindex)
         Rpart = filename.SubString(lindex)
      End If
      temp=1
      Do Until Not( File.Exists(dir, lpart & Append.Replace("#", temp) & rpart))
         temp=temp+1
      Loop
      Return lpart & Append.Replace("#", temp) & rpart
   Else
      Return filename
   End If
End Sub
Sub SaveScreenshot(BG As Canvas, Dir As String, FilenamePNG As String )As String 
   Dim Out As OutputStream
   FilenamePNG=UniqueFilename(dir, FilenamePNG, "")
   Out = File.OpenOutput(Dir, FilenamePNG, False)
   BG.Bitmap.WriteToStream(out, 100, "PNG")
   Out.Close
   Return Dir & "/" & FilenamePNG
End Sub

Then just call it via:

B4X:
ToastMessageShow( SaveScreenshot(BG, File.DirRootExternal, "Screenshot.PNG") ,True)
 
Last edited:

thedesolatesoul

Expert
Licensed User
Longtime User
I'm sorry, I'm not sure if I understand what your initial question was.
It seems like you are suggesting to use a Canvas to take a screenshot of the activity instead of the screenshot tool in the SDK.
I would agree with this especially for animations and graphics.

I think the difference is that the screenshot tool probably directly accesses the framebuffer (fb0) and reads out from memory. There could be writes going into the framebuffer so you get half the previous image and half the next image. Also, it probably has lower priority over resources making it slower.
Using your method using a canvas, since the code is sequential, it only reads out from memory after the whole canvas bitmap has been updated.
 
Upvote 0
Top