Android Question CameraEx2 getSupportedPreviewFormats

Discussion in 'Android Questions' started by walterf25, Jul 9, 2019.

  1. walterf25

    walterf25 Well-Known Member Licensed 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
     
  2. José J. Aguilar

    José J. Aguilar Active Member Licensed User

    I think you don't need JavaObject.

    Try something like this:
    Code:
    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]
     
    DonManfred and Erel like this.
  3. walterf25

    walterf25 Well-Known Member Licensed 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:
    Code:
    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
     
  4. Erel

    Erel Administrator Staff Member Licensed User

    Add this to CamEx2:
    Code:
    Public Sub getSupportedOutputFormats As Int()
       
    Dim StreamConfigurationMap As JavaObject = jcamera.RunMethod("GetScalerStreamConfiguration"Array(id))
       
    Return StreamConfigurationMap.RunMethod("getOutputFormats"Null)
    End Sub
     
    walterf25 and José J. Aguilar like this.
  5. walterf25

    walterf25 Well-Known Member Licensed User

    Thank you @Erel, this worked great, i get the following formats are supported.
    If I pass 35 as a parameter to this function in the Camex2 Class library
    Code:
    '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, 350False'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
     
  6. Erel

    Erel Administrator Staff Member Licensed User

    35 is the default preview format:
    Code:
    Camera.StartSession(tv, PreviewSize, CaptureSize, 25635False)
    You are passing 0.
     
    José J. Aguilar likes this.
  7. walterf25

    walterf25 Well-Known Member Licensed User

    I tried this and it works but i still don't see the camera_previewtaken(Image As Object) event being raised.
    Walter
     
  8. Erel

    Erel Administrator Staff Member Licensed User

    You should instead use a timer and call CamEx2.GetPreviewBitmap.
     
Loading...
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice