-
public abstract class CameraPreview<T extends View, Output>A CameraPreview takes in input stream from the CameraEngine, and streams it into an output surface that belongs to the view hierarchy.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description public interfaceCameraPreview.SurfaceCallbackThis is used to notify CameraEngine to recompute its camera Preview size.After that, CameraView will need a new layout pass to adapt to the Preview size.
-
Constructor Summary
Constructors Constructor Description CameraPreview(Context context, ViewGroup parent)Creates a new preview.
-
Method Summary
Modifier and Type Method Description voidsetSurfaceCallback(@Nullable() CameraPreview.SurfaceCallback callback)Sets a callback to be notified of surface events (creation, change, destruction) final TgetView()Returns the view hosting the Surface. abstract ViewgetRootView()For testing purposes, should return the root view that was inflated into theparent during onCreateView. abstract OutputgetOutput()Returns the output surface object (for example a SurfaceHolderor a SurfaceTexture). abstract Class<Output>getOutputClass()Returns the type of the output returned by getOutput. voidsetStreamSize(int width, int height)Called to notify the preview of the input stream size. final SizegetSurfaceSize()Returns the current output surface size, in view coordinates. final booleanhasSurface()Whether we have a valid surface already. voidonResume()Called by the hosting com.otaliastudios.cameraview.CameraView,this is a lifecycle event. voidonPause()Called by the hosting com.otaliastudios.cameraview.CameraView,this is a lifecycle event. voidonDestroy()Called by the hosting com.otaliastudios.cameraview.CameraView,this is a lifecycle event. booleansupportsCropping()Whether this preview implementation supports cropping.The base implementation does not, but it is strongly recommended to do so. booleanisCropping()Whether we are currently cropping the output.If false, this means that the output image will match the visible bounds. voidsetDrawRotation(int drawRotation)Should be called after setStreamSize!Sets the rotation, if any, to be applied when drawing. -
-
Method Detail
-
setSurfaceCallback
void setSurfaceCallback(@Nullable() CameraPreview.SurfaceCallback callback)
Sets a callback to be notified of surface events (creation, change, destruction)
- Parameters:
callback- a callback
-
getRootView
@NonNull() abstract View getRootView()
For testing purposes, should return the root view that was inflated into theparent during onCreateView.
-
getOutput
@NonNull() abstract Output getOutput()
Returns the output surface object (for example a SurfaceHolderor a SurfaceTexture).
-
getOutputClass
@NonNull() abstract Class<Output> getOutputClass()
Returns the type of the output returned by getOutput.
-
setStreamSize
void setStreamSize(int width, int height)
Called to notify the preview of the input stream size. The width and height must berotated before calling this, if needed, to be consistent with the VIEW reference.
- Parameters:
width- width of the preview stream, in view coordinatesheight- height of the preview stream, in view coordinates
-
getSurfaceSize
@NonNull() final Size getSurfaceSize()
Returns the current output surface size, in view coordinates.
-
hasSurface
final boolean hasSurface()
Whether we have a valid surface already.
-
onResume
void onResume()
Called by the hosting com.otaliastudios.cameraview.CameraView,this is a lifecycle event.
-
onPause
void onPause()
Called by the hosting com.otaliastudios.cameraview.CameraView,this is a lifecycle event.
-
onDestroy
@CallSuper() void onDestroy()
Called by the hosting com.otaliastudios.cameraview.CameraView,this is a lifecycle event.
-
supportsCropping
boolean supportsCropping()
Whether this preview implementation supports cropping.The base implementation does not, but it is strongly recommended to do so.
-
isCropping
boolean isCropping()
Whether we are currently cropping the output.If false, this means that the output image will match the visible bounds.
-
setDrawRotation
void setDrawRotation(int drawRotation)
Should be called after setStreamSize!Sets the rotation, if any, to be applied when drawing.Sometimes we don't need this:- In Camera1, the buffer producer sets our Surface size and rotates it based on the valuethat we pass to setDisplayOrientation,so the stream that comes in is already rotated (if we apply SurfaceTexture transform).- In Camera2, for android.view.SurfaceView based previews, apparently it just worksout of the box. The producer might be doing something similar.But in all the other Camera2 cases, we need to apply this rotation when drawing the surface.Seems that Camera1 can correctly rotate the stream/transform to VIEW,while Camera2, that does not have any rotation API, will only rotate to BASE.That's why in Camera2 this angle is set as the offset between BASE and VIEW.
- Parameters:
drawRotation- the rotation in degrees
-
-
-
-