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
 
I think you don't need JavaObject.

Try something like this:
Code: Copy
    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
I think you don't need JavaObject.

Try something like this:
Code: Copy
    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]
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:
Code: Copy
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
Add this to CamEx2:
Code: Copy
Public Sub getSupportedOutputFormats As Int()
   Dim StreamConfigurationMap As JavaObject = jcamera.RunMethod("GetScalerStreamConfiguration", Array(id))
   Return StreamConfigurationMap.RunMethod("getOutputFormats", Null)
End Sub
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
Code: Copy
'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?

Start success: true
format: 32
format: 256
format: 34
format: 35
Error occurred on line: 323 (CamEx2)
java.lang.ClassCastException: android.media.ImageReader$SurfaceImage cannot be cast to byte[]
at b4a.example3.camex2$ResumableSub_TakePictureNow.resume(camex2.java:1842)
at anywheresoftware.b4a.shell.DebugResumableSub$DelegatableResumableSub.resumeAsUserSub(DebugResumableSub.java:48)
at java.lang.reflect.Method.invoke(Native Method)
at anywheresoftware.b4a.shell.Shell.runMethod(Shell.java:735)
at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:357)
at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:260)
at java.lang.reflect.Method.invoke(Native Method)
at anywheresoftware.b4a.ShellBA.raiseEvent2(ShellBA.java:144)
at anywheresoftware.b4a.BA.raiseEvent(BA.java:171)
at anywheresoftware.b4a.shell.DebugResumableSub$DelegatableResumableSub.resume(DebugResumableSub.java:43)
at anywheresoftware.b4a.BA.checkAndRunWaitForEvent(BA.java:245)
at anywheresoftware.b4a.ShellBA.raiseEvent2(ShellBA.java:137)
at anywheresoftware.b4a.BA$1.run(BA.java:330)
at android.os.Handler.handleCallback(Handler.java:873)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:214)
at android.app.ActivityThread.main(ActivityThread.java:7032)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:494)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:965)
** Activity (main) Pause, UserClosed = true **

Thanks,
Walter
 
Upvote 0
35 is the default preview format:
Code: Copy
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
Back
Top