Class CameraSession
java.lang.Object
com.codename1.camera.CameraSession
- All Implemented Interfaces:
AutoCloseable
Active camera session. Obtained from Camera#open(CameraInfo, CameraSessionOptions).
Only one CameraSession may be open at a time; opening a second throws
IllegalStateException. Closing the session releases the camera hardware
and invalidates any CameraView returned by #createView().
Sessions may be paused (releasing hardware while keeping the session object)
and resumed; this is the right pattern when the app temporarily uses the
classic com.codename1.capture.Capture API while a session is open, since
the OS-level camera device is single-tenant.
-
Method Summary
Modifier and TypeMethodDescriptionvoidBackwards-compatible alias for#setFrameListener(FrameListener).voidclose()Release the session.Create the live preview component.voidfocus(float xNorm, float yNorm) Request a focus operation at the normalized preview coordinate (0.0top-left,1.0bottom-right).getInfo()TheCameraInfofor the physical camera this session is attached to.The options the session was opened with.booleanisClosed()True once#close()has been called on this session.voidpause()Release the hardware but keep this session object alive.voidvoidresume()Re-acquire the hardware after#pause().voidSet the flash / torch behavior.voidInstall a frame listener.voidsetZoom(float ratio) Set the zoom ratio where1.0is no zoom and values above1.0zoom in.startVideoRecording(String filePath) Begin recording video to the given FileSystemStorage path.Capture a still photo with default options.takePhoto(PhotoCaptureOptions opts) Capture a still photo using the given options (size, quality, file path).
-
Method Details
-
createView
Create the live preview component. Each session owns one view; subsequent calls return the same instance. -
takePhoto
Capture a still photo with default options. -
takePhoto
Capture a still photo using the given options (size, quality, file path). The returnedAsyncResourceresolves on the EDT with the captured photo, or fires its error callback if capture fails. -
startVideoRecording
Begin recording video to the given FileSystemStorage path. The returnedVideoRecordingis the handle used to stop the recording. -
setFrameListener
Install a frame listener. At most one frame listener may be active per session; installing a second replaces the first. Passnullto remove. -
addFrameListener
Backwards-compatible alias for#setFrameListener(FrameListener). -
removeFrameListener
-
setFlashMode
Set the flash / torch behavior. No-op on cameras whoseCameraInfo#hasFlash()is false. -
setZoom
public void setZoom(float ratio) Set the zoom ratio where1.0is no zoom and values above1.0zoom in. The platform implementation clamps to the supported range. -
focus
public void focus(float xNorm, float yNorm) Request a focus operation at the normalized preview coordinate (0.0top-left,1.0bottom-right). -
getInfo
TheCameraInfofor the physical camera this session is attached to. -
getOptions
The options the session was opened with. Read-only snapshot; mutating it afterCamera#open(CameraInfo, CameraSessionOptions)has no effect. -
pause
public void pause()Release the hardware but keep this session object alive. Pair with#resume(). -
resume
public void resume()Re-acquire the hardware after#pause(). No-op if the session is already running. -
close
-
isClosed
public boolean isClosed()True once#close()has been called on this session.
-