Package 

Class CameraPreview


  • 
    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 interface CameraPreview.SurfaceCallback

      This 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 Detail

      • CameraPreview

        CameraPreview(Context context, ViewGroup parent)
        Creates a new preview.
        Parameters:
        context - a context
        parent - where to inflate our view
    • Method Detail

      • getView

        @NonNull() final T getView()

        Returns the view hosting the Surface.

      • 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).

      • 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 coordinates
        height - height of the preview stream, in view coordinates
      • hasSurface

         final boolean hasSurface()

        Whether we have a valid surface already.

      • 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