Android Question CameraEx2 getSupportedPreviewFormats

walterf25

Expert
Licensed User
Longtime User
Hi all, i was wondering if someone could tell me if it would be possible to get the supported preview formats using the CameraEx2 class, i'm not too familiar with JavaObject, i have tried but am not able to get anywhere, please if anyone has tried this before and can share the code it would be greatly appreciated.

Thanks,
Walter
 

josejad

Expert
Licensed User
Longtime User
I think you don't need JavaObject.

Try something like this:
B4X:
    Dim Cam As Camera2
    Dim l As List

    l.Initialize
    Cam.Initialize("Camera")
    l = Cam.GetSupportedPreviewSizes(0)
    Log(l)

(ArrayList) [4128x3096, 4128x2322, 3264x2448, 3264x1836, 3088x3088, 2048x1536, 2048x1152, 1920x1080, 1280x720, 960x720, 720x480, 640x480, 352x288, 320x240, 256x144, 176x144]
 
Upvote 0

walterf25

Expert
Licensed User
Longtime User
Thank you but i am referring to the PreviewFormat not PreviewSizes, for example NV21, Raw10 etc. i don't see that method being exposed in this library, but i'm assuming it can be done with JavaObject, i have tried the following:
B4X:
Dim JO As JavaObject
JO = Camera
JO.RunMethod("getPreviewFormats", null)
I get an error saying getPreviewFormats doesn't exist in the anywheresoftware.ba.cam2 class.

Thanks,
Walter
 
Upvote 0

walterf25

Expert
Licensed User
Longtime User
Thank you @Erel, this worked great, i get the following formats are supported.
format: 32
format: 256
format: 34
format: 35

If I pass 35 as a parameter to this function in the Camex2 Class library
B4X:
'Prepared the surface for still capture.
Public Sub PrepareSurface (MyTaskIndex As Int) As ResumableSub
    If MyTaskIndex <> TaskIndex Then Return False
    CloseSession
    Wait For (CreateSurface) Complete (Result As Boolean)
    If MyTaskIndex <> TaskIndex Then Return False
    Camera.StartSession(tv, PreviewSize, CaptureSize, 35, 0, False) '256 = JPEG
    Wait For Camera_SessionConfigured (Success As Boolean)
    If MyTaskIndex <> TaskIndex Then Return False
    Return Success
End Sub

Then I get the following error, any idea on how to go around that?


Thanks,
Walter
 
Upvote 0

walterf25

Expert
Licensed User
Longtime User
35 is the default preview format:
B4X:
Camera.StartSession(tv, PreviewSize, CaptureSize, 256, 35, False)

You are passing 0.
I tried this and it works but i still don't see the camera_previewtaken(Image As Object) event being raised.
Walter
 
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…