Android Question focus mavic camera

shb777

Active Member
Licensed User
Longtime User
I flew my mavic drone close to dusk today, with my b4a program, but the video was out of focus
the whole time, and I found I had no way to focus with my program. Is there any way to focus,
like the dji go 4 touch to focus? steve
 

Erel

B4X founder
Staff member
Licensed User
Longtime User
You can use this code to set the focus target:
https://developer.dji.com/api-refer...mera_camerasettings_setlensfocustarget_inline
B4X:
Sub SetCameraFocusTarget(x As Float, y As Float)
   Dim pf As JavaObject
   pf.InitializeNewInstance("android.graphics.PointF", Array(x, y))
   Dim cc As Object = pf.CreateEventFromUI("dji.common.util.CommonCallbacks$CompletionCallback", "callback", Null)
   GetNativeCamera.RunMethod("setFocusTarget", Array(pf, cc))
   Wait For (pf) Callback_Event (MethodName As String, Args() As Object)
   If Args(0) = Null Then
     Log("Focus set successfully.")
   Else
     Log("Error setting focus: " & Args(0))
   End If
End Sub

Sub GetNativeCamera As JavaObject
   Dim jo As JavaObject = camera
   Return jo.GetFieldJO("camera")
End Sub
Note that the x and y values are between 0 to 1.

You can handle the pnlCamera touch event and then call SetCameraFocusTarget.
 
Upvote 0

shb777

Active Member
Licensed User
Longtime User
You can use this code to set the focus target:
https://developer.dji.com/api-refer...mera_camerasettings_setlensfocustarget_inline
B4X:
Sub SetCameraFocusTarget(x As Float, y As Float)
   Dim pf As JavaObject
   pf.InitializeNewInstance("android.graphics.PointF", Array(x, y))
   Dim cc As Object = pf.CreateEventFromUI("dji.common.util.CommonCallbacks$CompletionCallback", "callback", Null)
   GetNativeCamera.RunMethod("setFocusTarget", Array(pf, cc))
   Wait For (pf) Callback_Event (MethodName As String, Args() As Object)
   If Args(0) = Null Then
     Log("Focus set successfully.")
   Else
     Log("Error setting focus: " & Args(0))
   End If
End Sub

Sub GetNativeCamera As JavaObject
   Dim jo As JavaObject = camera
   Return jo.GetFieldJO("camera")
End Sub
Note that the x and y values are between 0 to 1.

You can handle the pnlCamera touch event and then call SetCameraFocusTarget.


OK thanks. so the middle of the screen would be 0.5, 0.5
 
Upvote 0

shb777

Active Member
Licensed User
Longtime User
tested it outdoors yesterday. works great! did you just do this for me? i have to learn how to do these java objects. steve
 
Upvote 0
Top