Android Question Screenshot of Camera preview

peacemaker

Expert
Licensed User
Longtime User
HI, All

Who tried this ?
If to use Erel's code
B4X:
Sub Take_Screenshot 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

the full screen camera preview is not shot :(
Maybe any solution to see the camera by the screenshot ?
Or any other variant to make pseudo live-video from remote smartphone with open camera ?

Now auto-refresh HTML-page shows OK:

B4X:
<html>
<head>
<meta http-equiv="Refresh" content="10" />
<meta http-equiv="Cache-Control" content="no-cache" />
</head>
<body>
<img src="http://ftp.kjhwdckj/screenshots/erwwrg9021b0.png" alt="РScreenshot">
</body>
</html>

But no camera's picture.
 

Peter Simpson

Expert
Licensed User
Longtime User
the full screen camera preview is not shot :(
But no camera's picture.

What exactly do you mean, please explain in more detail?

I just tried the code above and I added RuntimePermissions so that I could save the file easily and it worked as I would have expected it to do so.

B4X:
    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
 
    Private RTP As RuntimePermissions
    Log(RTP.GetSafeDirDefaultExternal(""))
    Dim Out As OutputStream
    Out = File.OpenOutput(RTP.GetSafeDirDefaultExternal(""), "Test.png", False)
    bmp.WriteToStream(Out, 100, "PNG")
    Out.Close

Look at the attached screenshot...
 

Attachments

  • e61c3444-5cb9-4df5-84b6-8c8fad496c9d.jpg
    e61c3444-5cb9-4df5-84b6-8c8fad496c9d.jpg
    12 KB · Views: 254
Upvote 0

peacemaker

Expert
Licensed User
Longtime User
I do not see camera's preview on the screenshot. Like in my project.
 
Upvote 0

peacemaker

Expert
Licensed User
Longtime User
SOLVED2: actually i could even "cook" the camera's screenshot myself :) ... combining camera's JPG with system screenshot. "iv" is a hidden ImageView.
"LastCadr" is latest camera's preview bitmap.

B4X:
        Dim r As B4XRect
        r.Initialize(0, 0, GetDeviceLayoutValues.Width, GetDeviceLayoutValues.Height)
        iv.Width = GetDeviceLayoutValues.Width
        iv.Height = GetDeviceLayoutValues.Height
        Dim can As B4XCanvas
        iv.Bitmap = Null
        can.Initialize(iv)
        can.ClearRect(can.TargetRect)
      
        can.DrawBitmap(LastCadr, r)
        Dim TitleHeight As Float = (GetDeviceLayoutValues.Height - Activity.Height)
      
        Dim b As B4XBitmap = others.Take_Screenshot
        r.Initialize(0, -TitleHeight, GetDeviceLayoutValues.Width, GetDeviceLayoutValues.Height-TitleHeight)
        can.DrawBitmap(b, r)
      
        can.Invalidate
And can.CreateBitmap is used where needed.
Note that such screenshot has no the system notification area. It's not screenshoted.
 
Upvote 0
Top