Android Question Camera Error in CommitParameters

Pedro Caldeira

Active Member
Licensed User
Longtime User
Hello,
I cannot focus or zoom the camera in most of the devices, however the Example works fine.
I always get : (RuntimeException) java.lang.RuntimeException: setParameters failed
Even in something as simple as :
B4X:
Sub camPanel_Ready (Success As Boolean)
    If Success Then
        camEx.SetContinuousAutoFocus
        camEx.SetJpegQuality(ShareCode.DEVICE_DEF_QUALITY)
        camEx.SetPictureSize(ShareCode.DEVICE_DEF_IMG_WIDTH,ShareCode.DEVICE_DEF_IMG_HEIGHT)
        camEx.CommitParameters
        camEx.StartPreview
      
        HasFocus = False      
        btnFocus.Enabled = False
        Dim fm As List = camEx.GetSupportedFocusModes
        For n=0 To fm.Size -1
            If fm.Get(n) = "auto" Then
                 HasFocus = True
                btnFocus.Enabled = True
            End If
        Next
      
    Else
        ToastMessageShow("Error opening camera.", True)
    End If
End Sub

Even the zoom get me the same error.

The native android camera zooms ans focus just fine
Any ideas ?
 

drgottjr

Expert
Licensed User
Longtime User
3 comments:
1) you set continuous auto focus before finding out if it's available.
2) you set picture size without testing whether the dimensions are available.
(also, i'm guessing your ShareCode.DEVICE_DEF_IMG_WIDTH,ShareCode.DEVICE_DEF_IMG_HEIGHT
values are legitimate.)
3) the continuous auto focus setting is probably the issue. comment it out and try again.
 
Upvote 0

Pedro Caldeira

Active Member
Licensed User
Longtime User
3 comments:
1) you set continuous auto focus before finding out if it's available.
2) you set picture size without testing whether the dimensions are available.
(also, i'm guessing your ShareCode.DEVICE_DEF_IMG_WIDTH,ShareCode.DEVICE_DEF_IMG_HEIGHT
values are legitimate.)
3) the continuous auto focus setting is probably the issue. comment it out and try again.
1) the countinuous autofocus sub in the CameraExClass has alterady a test for it
B4X:
Public Sub SetContinuousAutoFocus
    Dim modes As List = GetSupportedFocusModes
    If modes.IndexOf("continuous-picture") > -1 Then
        SetFocusMode("continuous-picture")
    Else If modes.IndexOf("continuous-video") > -1 Then
        SetFocusMode("continuous-video")
    Else
        Log("Continuous focus mode is not available")
    End If
End Sub
2) I am going to verify the variables to the picture size
3) I doubt that it is the issue, because the standard zoom function as in Erel's example (that works), returns the same error commiting
 
Upvote 0

Pedro Caldeira

Active Member
Licensed User
Longtime User
its solved. It was the
camEx.SetPictureSize(ShareCode.DEVICE_DEF_IMG_WIDTH,ShareCode.DEVICE_DEF_IMG_HEIGHT)
I was setting invalid values for some devices.
Thanks
 
Upvote 1
Top