Android Question What does cam.SupportedCaptureSizes return?

MrKim

Well-Known Member
Licensed User
Longtime User
Sigh, the little things continue to baffle me. Using CamEx2 (Camera2). I want to set the camera resolution.
I figured out how to get a list of available resolutions.
Code: Copy
Dim Reses As List = cam.SupportedCaptureSizes
It returns values that look like like: 640x480

Perfect, I thought I will parse out the 640 and 480 and use those with:

CaptureSize.Initialize(W, H) to set the size.

Unfortunately I cannot figure out what kind of object is returned by cam.SupportedCaptureSizes.
So I can't set it to a string to parse.
Code: Copy
Dim T as string
T=Value
returns "Error evaluating expression."

What am I missing?
Is there an easier way?

Thanks.
 
It returns Object CameraSize resp. a list of CameraSize objects
Code: Copy
Public PreviewSize, CaptureSize As CameraSize
    PreviewSize.Initialize(1920, 1080)
   CaptureSize.Initialize(1920, 1080)
 
Upvote 0
It returns Object CameraSize resp. a list of CameraSize objects
Code: Copy
Public PreviewSize, CaptureSize As CameraSize
    PreviewSize.Initialize(1920, 1080)
   CaptureSize.Initialize(1920, 1080)
But that still doesn't tell me how to get the Width and Height out of it so I can use it with CaptureSize.Initialize
 
Upvote 0
omg


Code: Copy
Dim Reses As List = cam.SupportedCaptureSizes
for i=0 to Reses.size-1
  dim size as CameraSize = Reses.Get(i)
 log(size)
next
I still can't seem to use it. Here is my code and what I see when running.

upload_2018-10-17_22-18-45.png

Log says
Code: Copy
(String) 320x240
but the H = T.Height line errors with
Code: Copy
java.lang.ClassCastException: java.lang.String cannot be cast to android.util.Size
And as you can see T.Height Appears to be invalid.

Well, I was able to get this to run:

Code: Copy
Sub ResList_ItemClick (Position As Int, Value As Object)
    Dim WH As String, H As Int, W As Int, T As CameraSize = Value
    Log (T)
    'T = Value =
    WH = T
    Log(WH)
    WH = WH.SubString(WH.IndexOf("(String)") + 9)
    H = WH.SubString2(1, WH.IndexOf("x"))
    W = WH.SubString(WH.IndexOf("x") + 1)
'    W = T.Width
    ToastMessageShow(Value & "  " & Position, False)
    cam.SetCaptureSize(W, H)
End Sub
But this seems kludgey. And I haven't really tested it yet to see if it does what I want.
I still want to know why the Height and Width Props of CameraSize are not available.
It is late here and I am tired and going to bed. Thanks for your help.
 
Upvote 0
That's true.

DonManfred's code is correct.

You haven't posted enough code for us to say where is the object converted to string.
a
  1. Your right, it was late and I was tired. I am putting the SupportedCaptureSizes in ResList ListView, then picking from the list. Two relevant subs are below. I set Value to T but T.Height and T.Width both say 'Error Evaluating Expression' as shown above. So I set
    Code: Copy
    WH = T
    to convert to string which gives the warning "Object Converted to string. This is probably a programming mistake." I then parse out the Height and Width, which seems to work.

Code: Copy
Sub BtnRes_Click
    Dim X As Int
    Dim Reses As List = cam.SupportedCaptureSizes
    ResList.Visible = Not(ResList.Visible)
    ResList.Left = btnEffects.Left+btnEffects.Width + 20dip
    ResList.Top = btnCamera.Top
    ResList.BringToFront
    ResList.Clear
    For X = 0 To Reses.Size - 1
        ResList.AddSingleLine(Reses.Get(X))
    Next

End Sub

Sub ResList_ItemClick (Position As Int, Value As Object)
    Dim WH As String, H As Int, W As Int, T As CameraSize = Value
    Log (T)
    T = Value
    WH = T
    Log(WH)
    WH = WH.SubString(WH.IndexOf("(String)") + 8)
    H = WH.SubString2(1, WH.IndexOf("x"))
    W = WH.SubString(WH.IndexOf("x") + 1)
    ToastMessageShow(Value & "  " & Position, False)
    cam.SetCaptureSize(W, H)

End Sub
 
Upvote 0
That's true.

DonManfred's code is correct.

You haven't posted enough code for us to say where is the object converted to string.
DOH!
My bad, I was thinking a ListView stored an object, not a string. Interesting that
Code: Copy
ResList.AddSingleLine(Reses.Get(X))
is perfectly happy to convert CameraSize to a string. And likewise
Code: Copy
Dim T As CameraSize = Value
was perfectly happy to set the ListView Value back to a CameraSize

Anyway here is what works:
Code: Copy
Sub Process_Globals
    Public PWidth As Int = 1920
    Public PHeight As Int = 1080
End Sub

Sub Globals
    Private ResList As ListView
    Private Reses As List
End Sub
.
.
.
.
Sub BtnRes_Click
    Dim X As Int

    Reses.Initialize2(cam.SupportedCaptureSizes)
    ResList.Left = btnEffects.Left+btnEffects.Width + 20dip
    ResList.Top = btnCamera.Top
    ResList.BringToFront
    ResList.Clear
    For X = 0 To Reses.Size - 1
        ResList.AddSingleLine(Reses.Get(X))
    Next

End Sub

Sub ResList_ItemClick (Position As Int, Value As Object)
    Dim T As CameraSize = Reses.Get(Position)
    PWidth = T.Width
    PHeight = T.Height
    cam.SetCaptureSize(PWidth, PHeight)
End Sub

Had to make PWidth and PHeight global and use them in CamEx2 as it re-initializes when you rotate the tablet.

Thanks for your time and I apologize for missing something so obvious.
 
Upvote 0
Back
Top