public interface Camera
A camera object can be obtained only in the following way:
Create a camera by calling CameraKit.createCamera(String, CameraStateCallback,
EventHandler), and get camera running states by calling CameraStateCallback.
The recommended operation steps are as follows:
CameraKit.createCamera(String, CameraStateCallback,
EventHandler). If the camera is successfully created, CameraStateCallback#onCreated(Camera) is called.
Otherwise, CameraStateCallback#onCreateFailed(String, int) is called.
CameraConfig.Builder instance by calling
Camera#getCameraConfigBuilder(), and then configure the camera by calling
Camera#configure(CameraConfig). If the camera is successfully configured,
CameraStateCallback#onConfigured(Camera) is called. Otherwise,
CameraStateCallback#onConfigureFailed(Camera, int) is called.
FrameConfig instance by FrameConfig.Builder, and then call
Camera#triggerLoopingCapture(FrameConfig) to start looping-frame capture. Looping-frame capture is
commonly used for preview or recording. Call Camera#triggerLoopingCapture(FrameConfig) to update
configuration of looping-frame capture.
FrameConfig instance by FrameConfig.Builder,
and then call Camera#triggerSingleCapture(FrameConfig) to start single-frame capture.
Single-frame capture is commonly used for taking a picture.
Camera#stopLoopingCapture().
Camera#release().
SystemCapability.Multimedia#CAMERA| 限定符和类型 | 接口 | 说明 |
|---|---|---|
static interface |
Camera.FrameConfigType |
Provides frame configuration types.
|
| 限定符和类型 | 字段 | 说明 |
|---|---|---|
static int |
CAPTURE_TRIGGER_ERROR_ID |
Indicates an invalid capture trigger ID.
|
| 限定符和类型 | 方法 | 说明 |
|---|---|---|
void |
configure(CameraConfig config) |
Configures the camera.
|
void |
flushCaptures() |
Immediately stops frame captures, including looping-frame, single-frame, and multi-frame captures.
|
CameraConfig.Builder |
getCameraConfigBuilder() |
Gets a
CameraConfig.Builder instance. |
String |
getCameraId() |
Gets the camera ID.
|
FrameConfig.Builder |
getFrameConfigBuilder(int type) |
Gets a specified type of
FrameConfig.Builder instance. |
void |
release() |
Releases the camera.
|
void |
stopLoopingCapture() |
Stops looping-frame capture.
|
int |
triggerLoopingCapture(FrameConfig frameConfig) |
Starts looping-frame capture.
|
int |
triggerLoopingGroupCapture(List<FrameConfig> frameConfigs) |
Starts looping-frame capture based on a group of configurations.
|
int |
triggerMultiCapture(List<FrameConfig> frameConfigs) |
Starts multi-frame capture.
|
int |
triggerSingleCapture(FrameConfig frameConfig) |
Starts single-frame capture.
|
static final int CAPTURE_TRIGGER_ERROR_ID
String getCameraId()
CameraConfig.Builder getCameraConfigBuilder()
CameraConfig.Builder instance.CameraConfig.Builder instance.FrameConfig.Builder getFrameConfigBuilder(int type)
FrameConfig.Builder instance.type - Indicates the frame configuration type.FrameConfig.Builder instance.IllegalArgumentException - Throws this exception if the frame configuration type is not supported.Camera.FrameConfigTypevoid configure(CameraConfig config)
Before using this method, call Camera#getCameraConfigBuilder() to obtain a
CameraConfig.Builder instance. This method is mainly used to set a surface for preview, taking pictures,
or recording. The preview surface must be configured, and the other two surfaces are optional.
If the camera is successfully configured, CameraStateCallback#onConfigured(Camera) will be called.
In this case, the camera becomes operable.
config - Indicates camera configuration parameters.NullPointerException - Throws this exception if camera configuration is null.IllegalArgumentException - Throws this exception if a parameter value is invalid. For example, the camera
configuration is null, or the surface is null.IllegalStateException - Throws this exception if the camera is released or if an error occurs.void release()
AAfter the camera is released, it will become unavilable for operations. Any operation on it will cause an unexpected result or exception.
int triggerLoopingCapture(FrameConfig frameConfig)
Looping-frame capture is commonly used for preview or recording. Ensure the following conditions are met when calling this method:
CameraStateCallback#onConfigured(Camera) has been called.
CameraConfig.Builder#addSurface(Surface).
frameConfig - Indicates the looping-frame capture configuration.IllegalArgumentException - Throws this exception if configuration of the camera or surface is null.IllegalStateException - Throws this exception if the camera is not in the configured state.int triggerLoopingGroupCapture(List<FrameConfig> frameConfigs)
You can use this method for differentiated frame rate control when there are multiple concurrent streams. Ensure the following conditions are met when calling this method:
CameraStateCallback#onConfigured(Camera) has been called.
CameraConfig.Builder#addSurface(Surface).
frameConfigs - Indicates a group of frame configurations.IllegalArgumentException - Throws this exception if the camera or the surface is not configured.IllegalStateException - Throws this exception if the camera is not in the configured state.void stopLoopingCapture()
IllegalStateException - Throws this exception if the camera is not in the configured state.int triggerSingleCapture(FrameConfig frameConfig)
This method is commonly used for taking a picture.
Before taking a picture, the camera must start looping-frame capture. The configuration of this capture will be inserted into the looping capture queue. Surfaces in the looping-frame capture configuration should also be included in this single-frame capture to obtain continuous preview or video images.
frameConfig - Indicates single-frame capture configuration.IllegalArgumentException - Throws this exception if the camera or the surface is not configured.IllegalStateException - Throws this exception if the camera is not in the configured state.int triggerMultiCapture(List<FrameConfig> frameConfigs)
Before taking a picture, looping-frame capture must be started. The configuration of those shoots will be inserted into the looping capture queue. Surfaces in the looping-frame capture configuration should also be included in this multi-frame capture to obtain continuous preview or video images.
frameConfigs - Indicates multi-frame capture configuration.IllegalArgumentException - Throws this exception if the camera or the surface is not configured.IllegalStateException - Throws this exception if the camera is not in the configured state.void flushCaptures()
Some in-flight captures may call
FrameStateCallback#onFrameError(Camera, FrameConfig, int, FrameResult).
IllegalStateException - Throws this exception if the camera is not in the configured state.