public class CameraSource
extends java.lang.Object
Modifier and Type | Class and Description |
---|---|
static interface |
CameraSource.AutoFocusCallback
Callback interface used to notify on completion of camera auto focus.
|
static interface |
CameraSource.AutoFocusMoveCallback
Callback interface used to notify on auto focus start and stop.
|
static class |
CameraSource.Builder
Builder class for configuring and creating an associated camera source.
|
static interface |
CameraSource.PictureCallback
Callback interface used to supply image data from a photo capture.
|
static interface |
CameraSource.ShutterCallback
Callback interface used to signal the moment of actual image capture.
|
Modifier and Type | Field and Description |
---|---|
static int |
CAMERA_FACING_BACK |
static int |
CAMERA_FACING_FRONT |
Modifier and Type | Method and Description |
---|---|
void |
autoFocus(CameraSource.AutoFocusCallback cb)
Starts camera auto-focus and registers a callback function to run when
the camera is focused.
|
void |
cancelAutoFocus()
Cancels any auto-focus function in progress.
|
int |
doZoom(float scale) |
int |
getCameraFacing()
Returns the selected camera; one of
CAMERA_FACING_BACK or
CAMERA_FACING_FRONT . |
java.lang.String |
getFlashMode()
Gets the current flash mode setting.
|
java.lang.String |
getFocusMode()
Gets the current focus mode setting.
|
com.google.android.gms.common.images.Size |
getPreviewSize()
Returns the preview size that is currently in use by the underlying camera.
|
void |
release()
Stops the camera and releases the resources of the camera and underlying detector.
|
boolean |
setAutoFocusMoveCallback(CameraSource.AutoFocusMoveCallback cb)
Sets camera auto-focus move callback.
|
boolean |
setFlashMode(java.lang.String mode)
Sets the flash mode.
|
boolean |
setFocusMode(java.lang.String mode)
Sets the focus mode.
|
CameraSource |
start()
Opens the camera and starts sending preview frames to the underlying detector.
|
CameraSource |
start(android.view.SurfaceHolder surfaceHolder)
Opens the camera and starts sending preview frames to the underlying detector.
|
void |
stop()
Closes the camera and stops sending frames to the underlying frame detector.
|
void |
takePicture(CameraSource.ShutterCallback shutter,
CameraSource.PictureCallback jpeg)
Initiates taking a picture, which happens asynchronously.
|
public static final int CAMERA_FACING_BACK
public static final int CAMERA_FACING_FRONT
public void release()
public CameraSource start() throws java.io.IOException, java.lang.SecurityException
java.io.IOException
- if the camera's preview texture or display could not be initializedjava.lang.SecurityException
public CameraSource start(android.view.SurfaceHolder surfaceHolder) throws java.io.IOException, java.lang.SecurityException
java.io.IOException
- if the supplied surface holder could not be used as the preview displayjava.lang.SecurityException
public void stop()
start()
or
start(SurfaceHolder)
.
Call release()
instead to completely shut down this camera source and release the
resources of the underlying detector.public com.google.android.gms.common.images.Size getPreviewSize()
public int getCameraFacing()
CAMERA_FACING_BACK
or
CAMERA_FACING_FRONT
.public int doZoom(float scale)
public void takePicture(CameraSource.ShutterCallback shutter, CameraSource.PictureCallback jpeg)
start()
or start(SurfaceHolder)
. The camera
preview is suspended while the picture is being taken, but will resume once picture taking is
done.shutter
- the callback for image capture moment, or nulljpeg
- the callback for JPEG image data, or null@Nullable public java.lang.String getFocusMode()
autoFocus(AutoFocusCallback)
to start the focus if focus
mode is FOCUS_MODE_AUTO or FOCUS_MODE_MACRO.Camera.Parameters#FOCUS_MODE_AUTO
,
Camera.Parameters#FOCUS_MODE_INFINITY
,
Camera.Parameters#FOCUS_MODE_MACRO
,
Camera.Parameters#FOCUS_MODE_FIXED
,
Camera.Parameters#FOCUS_MODE_EDOF
,
Camera.Parameters#FOCUS_MODE_CONTINUOUS_VIDEO
,
Camera.Parameters#FOCUS_MODE_CONTINUOUS_PICTURE
public boolean setFocusMode(java.lang.String mode)
mode
- the focus modetrue
if the focus mode is set, false
otherwisegetFocusMode()
@Nullable public java.lang.String getFlashMode()
Camera.Parameters#FLASH_MODE_OFF
,
Camera.Parameters#FLASH_MODE_AUTO
,
Camera.Parameters#FLASH_MODE_ON
,
Camera.Parameters#FLASH_MODE_RED_EYE
,
Camera.Parameters#FLASH_MODE_TORCH
public boolean setFlashMode(java.lang.String mode)
mode
- flash mode.true
if the flash mode is set, false
otherwisegetFlashMode()
public void autoFocus(@Nullable CameraSource.AutoFocusCallback cb)
start()
or start(SurfaceHolder)
and before stop()
or release()
).
Callers should check
getFocusMode()
to determine if
this method should be called. If the camera does not support auto-focus,
it is a no-op and CameraSource.AutoFocusCallback.onAutoFocus(boolean)
callback will be called immediately.
If the current flash mode is not
Camera.Parameters#FLASH_MODE_OFF
, flash may be
fired during auto-focus, depending on the driver and camera hardware.
cb
- the callback to runcancelAutoFocus()
public void cancelAutoFocus()
autoFocus(AutoFocusCallback)
public boolean setAutoFocusMoveCallback(@Nullable CameraSource.AutoFocusMoveCallback cb)
cb
- the callback to runtrue
if the operation is supported (i.e. from Jelly Bean), false
otherwise