In CamEx2 the Camera2 PreviewTaken (Image As Object) event is commented:
B4X:
'Private Sub Camera_PreviewTaken (Image As Object)
' Log(Image)
'End Sub
I tried uncommenting the Sub, but the event never happens:
B4X:
Private Sub Camera_PreviewTaken (Image As Object)
Log("PreviewTaken")
End Sub
The other preview event "PreviewCaptureComplete" happens very often:
B4X:
Private Sub Camera_PreviewCaptureComplete (CaptureResult As Object)
FocusState = IntToConst(GetFromCaptureResult(CaptureResult, "CONTROL_AF_STATE"), AF_STATE)
Log("PreviewCaptureComplete")
'Log(IntToConst(GetFromCaptureResult(CaptureResult, "FLASH_STATE"), FLASH_STATE))
'PrintAllKeys(CaptureResult, "Capture Result")
End Sub
I'm planning to change my app from useing Camera to Camera2 library. My app use the old camera library's event Preview (Data() As Byte) to examine the preview picture by code, so now I'm playing with the CamEx2 to understand how it could be done.
I forgot to tell: PreviewTaken event still do not raise, although I set the PreviewFormat parameter in the camera.StartSession to 35.
I made this sub:
B4X:
Public Sub getOutputFormats As Int()
Dim SCM As JavaObject = GetFromCameraCharacteristic("SCALER_STREAM_CONFIGURATION_MAP")
Dim OF() As Int = SCM.RunMethod("getOutputFormats", Array As Object())
For Each f As Int In OF
Log(f)
Next
Return OF
End Sub
Which gave me the following output formats: 32, 256, 34, 35, 36, 37
I have tried all of them:
Using outputformat 32, 256, 36 and 37 as PreviewFormat parameter causes "failed to open camera"
Using outputformat 36 and 37 opens the camera, shows preview on phone display, but the PreviewTaken does not raise.
I am sorry, the list of formats I tried was wrong. The correct list is
Using outputformat 32, 256, 36 and 37 as PreviewFormat parameter causes "failed to open camera"
Using outputformat 34 and 35 opens the camera, shows preview on phone display, but the PreviewTaken does not raise.
I have tried 35, on a phone and on a tablet. The PreviewTaken event does not raise on either of them.
I have now decided to use PreviewCaptureComplete something like this
B4X:
Private Sub Camera_PreviewCaptureComplete (CaptureResult As Object)
FocusState = IntToConst(GetFromCaptureResult(CaptureResult, "CONTROL_AF_STATE"), AF_STATE)
Dim preview As Bitmap = GetPreviewBitmap(4,4)
'examine the preview picture here