camera zooming

danoptic

Member
Licensed User
Longtime User
Is that possible to zoom using any camera library?
please give me an example
Dan
 

Erel

B4X founder
Staff member
Licensed User
Longtime User
You can add these 3 methods to CameraEx class:
B4X:
Public Sub IsZoomSupported As Boolean
   r.target = parameters
   Return r.RunMethod("isZoomSupported")
End Sub
Public Sub GetMaxZoom As Int
   r.target = parameters
   Return r.RunMethod("getMaxZoom")
End Sub

Public Sub SetZoom(Zoom As Int)
   r.target = parameters
   r.RunMethod2("setZoom", Zoom, "java.lang.int")
End Sub
 
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
Note that it is better to start a new thread for a new question.

You can use this code:
B4X:
Public Sub GetFocusDistances As Float()
   Dim f(3) As Float
   r.Target = parameters
   r.RunMethod4("getFocusDistances", Array As Object(f), Array As String("[F"))
   Return f
End Sub

'call it
Dim f() As Float = camEx.GetFocusDistances
Log(f(0) & ", " & f(1) & ", " & f(2))

Seems like many devices doesn't support it properly:
Issue 14341 - android - Distances returned by Camera.Parameters.getFocusDistances() do not change on Nexus S regardless of actual focus distance - Android - An Open Handset Alliance Project - Google Project Hosting
 
Upvote 0

cluster1

New Member
Licensed User
Longtime User
ya, i have already added to method CameraEx class
e g :

Sub btnZoomin_Click
ToastMessageShow("Zoom in",True)
CamEx.GetMaxZoom
End Sub

but it's does'nt work
 
Upvote 0

udg

Expert
Licensed User
Longtime User
Hi cluster1,
are you looking for a way to start zooming on a button click? If yes, please find below some example code based on your own and what it is in post #2
B4X:
Sub btnZoomin_Click
  if CamEx.IsZoomSuported then
    dim maxZ as int
    maxZ = CamEx.GetMaxZoom
    CamEx.SetZoom(maxZ)
  else
     ToastMessageShow("Sorry, unable to zoom",True)
  end if
End Sub

udg
 
Upvote 0

吳界明

Member
Licensed User
Longtime User
I use the ZOOM method to do zoom in/out , but the scene of camera not becoming larger or smaller.
Who can provides the camera zooming example for me, thanks.
 
Upvote 0

吳界明

Member
Licensed User
Longtime User
Yes, I can use the zooming control, but when I execute the FocusAndTakePicture method, then the procedure will break and throw the exception error about autofocus
I think that is the java error when I use the cameraExclass


Public Sub FocusAndTakePicture
cam.AutoFocus
End Sub
 
Upvote 0

吳界明

Member
Licensed User
Longtime User
** Activity (main) Pause, UserClosed = true **
** Activity (main) Create, isFirst = true **
** Activity (main) Resume **
Error occurred on line: 316 (cameraexclass)
java.lang.NullPointerException
at anywheresoftware.b4a.objects.CameraW.AutoFocus(CameraW.java:191)
at Insert.water.gov.cameraexclass._focusandtakepicture(cameraexclass.java:534)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at anywheresoftware.b4a.shell.Shell.runMethod(Shell.java:636)
at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:302)
at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:238)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at anywheresoftware.b4a.ShellBA.raiseEvent2(ShellBA.java:121)
at anywheresoftware.b4a.BA.raiseEvent(BA.java:158)
at Insert.water.gov.main.afterFirstLayout(main.java:104)
at Insert.water.gov.main.access$100(main.java:16)
at Insert.water.gov.main$WaitForLayout.run(main.java:76)
at android.os.Handler.handleCallback(Handler.java:733)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:136)
at android.app.ActivityThread.main(ActivityThread.java:5050)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:780)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:596)
at dalvik.system.NativeStart.main(Native Method)
 
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…