Class CameraController
-
- All Implemented Interfaces:
public abstract class CameraControllerClass to abstract away camera api 1 and 2 differences.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description public enumCameraController.CameraOrientationHelper enum to be able to get the back camera orientation
public interfaceCameraController.CameraControllerListener
-
Method Summary
Modifier and Type Method Description CameraConfiggetPreferredCameraConfig()voidsetPreferredCameraConfig(@NonNull() CameraConfig preferredCameraConfig)Set the preferred camera settings. CameraConfiggetCameraConfig()Get the actually used settings (this is only available after the camera has been opened). booleanhasNewImage()AnylineYuvImagegetNewImage()AnylineImagegetLastImageWithFullSize()Get the latest image in full size. ImageReceivergetLastImageWithFullSizeReceiver()Get the a receiver for the latest image in full size. voidtakeHighResolutionImage()Takes a picture from the camera and calls onImageTaken after the image is taken successfully. voidtakeHighResolutionImage(int top, int left, int right, int bottom, int viewWidth, int viewHeight)voidsetHighResolutionImageListener(@Nullable() HighResolutionImageListener highResolutionImageListener)Sets an optional listener which is called with the final AnylineImage, once a picture was taken with the camera via the takeHighResolutionImage method. voidsetCameraOpenListener(@Nullable() CameraOpenListener listener)Set the listener that is called when the camera is opened or a camera related error occurred. voidremoveCameraOpenListener(CameraOpenListener listener)voidremoveAllCameraOpenListeners()voidsetImageListener(ImageListener imageListener)Set the listener that should be called when a new image is available abstract voidsetFlashOn(boolean isOn)Turn the torch flash on or off. voidsetZoomGestureEnabled(boolean isZoomEnabled)Enable zoom for the camera Needs to be called before setupZoomHandler() abstract voidsetupZoomHandler(View view)Set up the zoom for the camera doublegetFocalLength()Get custom zoom level abstract voidsetFocalLength(double focalLength)Set a zoom level through focal length abstract voidsetMaxFocalLength(double maxFocalLength)Set a maximum focal length abstract voidsetMaxZoomRatio(double maxZoomRatio)Set a maximum zoom ratio abstract doublegetZoomRatio()Get the current zoom ratio abstract voidsetZoomRatio(double zoomLevelRatio)Set a zoom level through zoom Ratio abstract doublegetCurrentFocalLength()Get the current focal length abstract voidcallAutoFocus()Call auto focus. voidresetAutoFocusTimer()Reset the auto focus timer, if a focus config is set. abstract voidreleaseCamera()Release the camera. abstract voidreleaseCameraAndPreview()Release the camera for the landscape to landscape mode. abstract voidopenCameraInBackground()Open the camera in a background thread, if surface is already created and camera is not opened already. abstract booleanopenCameraInBackgroundSuccessfully()abstract voidreleaseCameraInBackground()Release the camera in a background thread. ViewgetPreviewView()intgetFrameWidth()intgetFrameHeight()floatgetFrameToViewScale()floatgetFrameToViewScaleWidth()CameraFeaturesgetCameraFeatures()abstract CameraFeatures.LensFacinggetCameraLensFacing()abstract CameraController.CameraOrientationgetCameraOrientation()voidsetCameraOrientation(CameraController.CameraOrientation cameraOrientation)Allows you to set the camera orientation for the BACK camera. booleanisPreviewMirrored()voidsetFocusRegionToCutout(@NonNull() Context context, @NonNull() RectF cutOutRect, float surfaceWidth, float surfaceHeight)Updates the focus and metering region to be the same as the given cutout. voidsetFocusRegionToCutouts(@NonNull() Context context, @NonNull() List<Rect> cutOutRectList)Updates the focus and metering region to be the same for all given cutouts. voidsetCameraControllerListener(CameraController.CameraControllerListener cameraControllerListener)-
-
Method Detail
-
getPreferredCameraConfig
@NonNull() CameraConfig getPreferredCameraConfig()
- Returns:
the preferred camera settings
-
setPreferredCameraConfig
void setPreferredCameraConfig(@NonNull() CameraConfig preferredCameraConfig)
Set the preferred camera settings. The actual used settings will be composed of this and the available features.
- Parameters:
preferredCameraConfig- the preferred settings
-
getCameraConfig
@Nullable() CameraConfig getCameraConfig()
Get the actually used settings (this is only available after the camera has been opened).
This is for information purposes only (to see what settings are actually used). To change the settings use the getPreferredCameraConfig instead.
- Returns:
the actually used settings (or null if camera not yet opened)
-
hasNewImage
@Deprecated(since = "55.0.0") boolean hasNewImage()
- Returns:
true if a new image is available in the buffer
-
getNewImage
@Nullable()@Deprecated(since = "55.0.0") AnylineYuvImage getNewImage()
- Returns:
the next new image (sets hasNewImage to false until another image is available)
-
getLastImageWithFullSize
@Nullable()@Deprecated(since = "55.0.0") AnylineImage getLastImageWithFullSize()
Get the latest image in full size. This does not check or manipulate hasNewImage.
Prefer getLastImageWithFullSizeReceiver, if you are not sure if the image is actually needed, to save resources.
- Returns:
the latest image in full size.
-
getLastImageWithFullSizeReceiver
@Nullable()@Deprecated(since = "55.0.0") ImageReceiver getLastImageWithFullSizeReceiver()
Get the a receiver for the latest image in full size. This does not check or manipulate hasNewImage.
The receiver does not copy the image if no getter is called.
- Returns:
a receiver for the latest image in full size.
-
takeHighResolutionImage
@Deprecated(since = "55.0.0") void takeHighResolutionImage()
Takes a picture from the camera and calls onImageTaken after the image is taken successfully. If no HighResolutionImageListener is set, the method returns. Additionally, a picture is only taken if the safeToTakePicture flag is set to true, which means the camera is open and preview is started.
-
takeHighResolutionImage
@Deprecated(since = "55.0.0") void takeHighResolutionImage(int top, int left, int right, int bottom, int viewWidth, int viewHeight)
-
setHighResolutionImageListener
@Deprecated(since = "55.0.0") void setHighResolutionImageListener(@Nullable() HighResolutionImageListener highResolutionImageListener)
Sets an optional listener which is called with the final AnylineImage, once a picture was taken with the camera via the takeHighResolutionImage method.
- Parameters:
highResolutionImageListener- the listener to call if a picture was taken (or an error occured)
-
setCameraOpenListener
void setCameraOpenListener(@Nullable() CameraOpenListener listener)
Set the listener that is called when the camera is opened or a camera related error occurred. If not set the opening of the camera will be logged and an error will be thrown as a RuntimeException.
- Parameters:
listener- the listener
-
removeCameraOpenListener
void removeCameraOpenListener(CameraOpenListener listener)
-
removeAllCameraOpenListeners
void removeAllCameraOpenListeners()
-
setImageListener
void setImageListener(ImageListener imageListener)
Set the listener that should be called when a new image is available
- Parameters:
imageListener- the listener that should be notified if an image is available
-
setFlashOn
abstract void setFlashOn(boolean isOn)
Turn the torch flash on or off.
- Parameters:
isOn- true to turn the flash on false to turn it off
-
setZoomGestureEnabled
void setZoomGestureEnabled(boolean isZoomEnabled)
Enable zoom for the camera Needs to be called before setupZoomHandler()
-
setupZoomHandler
abstract void setupZoomHandler(View view)
Set up the zoom for the camera
-
getFocalLength
double getFocalLength()
Get custom zoom level
-
setFocalLength
abstract void setFocalLength(double focalLength)
Set a zoom level through focal length
-
setMaxFocalLength
abstract void setMaxFocalLength(double maxFocalLength)
Set a maximum focal length
-
setMaxZoomRatio
abstract void setMaxZoomRatio(double maxZoomRatio)
Set a maximum zoom ratio
-
getZoomRatio
abstract double getZoomRatio()
Get the current zoom ratio
-
setZoomRatio
abstract void setZoomRatio(double zoomLevelRatio)
Set a zoom level through zoom Ratio
-
getCurrentFocalLength
abstract double getCurrentFocalLength()
Get the current focal length
-
callAutoFocus
abstract void callAutoFocus()
Call auto focus.
-
resetAutoFocusTimer
void resetAutoFocusTimer()
Reset the auto focus timer, if a focus config is set.
-
releaseCamera
abstract void releaseCamera()
Release the camera.
ALWAYS call this or releaseCameraInBackground in onPause of your activity!!
-
releaseCameraAndPreview
abstract void releaseCameraAndPreview()
Release the camera for the landscape to landscape mode.
-
openCameraInBackground
abstract void openCameraInBackground()
Open the camera in a background thread, if surface is already created and camera is not opened already. Reports opening or error to the CameraOpenListener set with setCameraOpenListener.
-
openCameraInBackgroundSuccessfully
abstract boolean openCameraInBackgroundSuccessfully()
-
releaseCameraInBackground
abstract void releaseCameraInBackground()
Release the camera in a background thread. Camera releasing may take a bit, so it may interfere with your exit animation. Use this to do it in the background.
ALWAYS call this or releaseCamera in onPause of your activity!!
-
getPreviewView
View getPreviewView()
- Returns:
the view on which the preview is displayed
-
getFrameWidth
int getFrameWidth()
- Returns:
the width of the frames received (only available after the camera is opened)
-
getFrameHeight
int getFrameHeight()
- Returns:
the height of the frames received (only available after the camera is opened)
-
getFrameToViewScale
float getFrameToViewScale()
- Returns:
the scale, the ratio of the view size to the frame size (only available after the camera is opened)
-
getFrameToViewScaleWidth
float getFrameToViewScaleWidth()
-
getCameraFeatures
@Nullable() CameraFeatures getCameraFeatures()
- Returns:
the available camera features for the opened camera (will be null if no camera is open yet)
-
getCameraLensFacing
abstract CameraFeatures.LensFacing getCameraLensFacing()
-
getCameraOrientation
abstract CameraController.CameraOrientation getCameraOrientation()
- Returns:
the camera orientation (only available after the camera is opened)
-
setCameraOrientation
@Deprecated(since = "55.0.0") void setCameraOrientation(CameraController.CameraOrientation cameraOrientation)
Allows you to set the camera orientation for the BACK camera.
- Parameters:
cameraOrientation- represents orientation type
-
isPreviewMirrored
boolean isPreviewMirrored()
- Returns:
whether the preview is mirrored or not
-
setFocusRegionToCutout
@Deprecated(since = "55.0.0") void setFocusRegionToCutout(@NonNull() Context context, @NonNull() RectF cutOutRect, float surfaceWidth, float surfaceHeight)
Updates the focus and metering region to be the same as the given cutout.
- Parameters:
context- the contextcutOutRect- the cutout rect relative to the surfacesurfaceWidth- the width of the surfacesurfaceHeight- the height of the surface
-
setFocusRegionToCutouts
void setFocusRegionToCutouts(@NonNull() Context context, @NonNull() List<Rect> cutOutRectList)
Updates the focus and metering region to be the same for all given cutouts.
- Parameters:
context- the contextcutOutRectList- the list of cutout rects relative to the surface
-
setCameraControllerListener
void setCameraControllerListener(CameraController.CameraControllerListener cameraControllerListener)
-
-
-
-