How to make the camera preview process lighter

Marcob

Member
Licensed User
Longtime User
Hello,

my application has a timer initialized to 250 ms.
I noticed that when the camera preview is running, the timer event subroutine is invoked only about every 500 ms.
Is there a simple way to make the preview process less cumbersome (maybe decreasing resolution or frame rate) ?

Note: I'm using CameraExClass and the device is a Galaxy S (Android 4.2.2)

Thank you
 

Erel

B4X founder
Staff member
Licensed User
Longtime User
You can add these methods to CameraEx:
B4X:
'Returns a list with the supported preview fps. Each item in the list is an array of two ints (minimum value and maximum value).
Public Sub GetSupportedPreviewFpsRange As List
   r.Target = parameters
   Return r.RunMethod("getSupportedPreviewFpsRange")
End Sub
'Returns the current preview fps range.
'Range is a two elements array. The minimum value and maximum value will be stored in this array.
Public Sub GetPreviewFpsRange(Range() As Int)
   r.Target = parameters
   r.RunMethod4("getPreviewFpsRange", Array As Object(Range), Array As String("[I"))
End Sub

Public Sub SetPreviewFpsRange(MinValue As Int, MaxValue As Int)
   r.Target = parameters
   r.RunMethod4("setPreviewFpsRange", Array As Object(MinValue, MaxValue), _
      Array As String("java.lang.int", "java.lang.int"))
End Sub

See the documentation here: Camera.Parameters | Android Developers
 
Upvote 0

Marcob

Member
Licensed User
Longtime User
Thank Erel for your help.

Unfortunately using GetSupportedPreviewFpsRange I found that my device (Galaxy S) supports only the interval 15000-30000. I tried to force the range to 15000-15000 but that doesn't work.

I will try to make some tests by decreasing the preview resolution using the following methods:

B4X:
Public Sub GetSupportedPreviewSizes As CameraSize()
   r.target = parameters
   Dim list1 As List = r.RunMethod("getSupportedPreviewSizes")
   Dim cs(list1.Size) As CameraSize
   For i = 0 To list1.Size - 1
      r.target = list1.Get(i)
      cs(i).Width = r.GetField("width")
      cs(i).Height = r.GetField("height")
   Next
   Return cs
End Sub

Public Sub SetPreviewSize(Width As Int, Height As Int)
   r.target = parameters
   r.RunMethod3("setPreviewSize", Width, "java.lang.int", Height, "java.lang.int")
End Sub
 
Upvote 0
Top