Android Question Share App-View

D

Deleted member 103

Guest
Hi,

I share the appearance of my app with a second device, I use the example "MJPEG / CCTV Server" of Erel.
But not the camera is used, as in the example, but I send with a timer a few screenshot per second.
My question is: is there a better solution or is my approach right?

B4X:
Private Sub mirrorTimer_Tick
    'Log("mirrorTimer_Tick")
    Dim jpeg() As Byte = ConvertBitmapToByte(TakeScreenshot)
    Starter.smanager.NewBitmap(jpeg)
End Sub

Private Sub TakeScreenshot As Bitmap
    Dim jo As JavaObject
    jo.InitializeContext
    Dim decor As JavaObject = jo.RunMethodJO("getWindow", Null).RunMethod("getDecorView", Null)
    Dim decorChild As JavaObject = decor.RunMethod("getChildAt", Array(0))
    decorChild.RunMethod("setDrawingCacheEnabled", Array(True))
    decorChild.RunMethod("buildDrawingCache", Null)
    Dim bmp As Bitmap = decorChild.RunMethod("getDrawingCache", Array(True))
    bmp.Initialize3(bmp)
    decorChild.RunMethod("setDrawingCacheEnabled", Array(False))
    Return bmp
End Sub

Private Sub ConvertBitmapToByte(foto As Bitmap) As Byte()
    'convert the image file to a bytes array
    Dim OutputStream1 As OutputStream
    OutputStream1.InitializeToBytesArray(1000)
    'Dim InputStream1 As InputStream
    foto.WriteToStream(OutputStream1,70,"JPEG")
    Dim Buffer() As Byte 'declares an empty array
    Buffer = OutputStream1.ToBytesArray
    Return Buffer
End Sub
 

Erel

B4X founder
Staff member
Licensed User
Longtime User
I never worked with the ScreenRecorder library.

the app gets very sluggish over time.
This can probably be fixed.

Try to take the screenshot with this code:
B4X:
Dim x As B4XView = Activity
Dim bmp As Bitmap = x.Snapshot.Resize(600, 600, True)
 
Upvote 0
D

Deleted member 103

Guest
I never worked with the ScreenRecorder library.


This can probably be fixed.

Try to take the screenshot with this code:
B4X:
Dim x As B4XView = Activity
Dim bmp As Bitmap = x.Snapshot.Resize(600, 600, True)
Thanks Erel, I'll try it. :)
 
Upvote 0
D

Deleted member 103

Guest
Hi Erel,

I tried the new feature, it's really great! :)

You could have said that to me earlier.:mad:

No, joking aside, many thanks. ;)
 
Upvote 0
D

Deleted member 103

Guest
Hi Erel,

I have tried the same code for B4i, unfortunately it does not have the same performance in B4i as in B4a.
Is there anything better for B4i?

B4X:
Private Sub TakeScreenshot As Bitmap
    Dim x As B4XView = pMain.RootPanel
    Return x.Snapshot.Resize(600, 600, True)
End Sub
 
Upvote 0

ilan

Expert
Licensed User
Longtime User
Upvote 0
Top