Class CameraPreviewHelper


  • public class CameraPreviewHelper
    extends java.lang.Object
    Helper class for camera previews
    Since:
    2.4.0
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      android.util.Size getCorrectedTextureSize​(int imageWidth, int imageHeight, int viewWidth, int viewHeight, int sensorOrientation, int deviceRotation)
      Get camera preview texture size corrected to match the device and camera sensor orientation
      static CameraPreviewHelper getInstance()  
      int getMinImageArea()  
      android.util.Size[] getOutputSizes​(android.util.Size[] previewSizes, android.util.Size[] imageReaderSizes, android.util.Size[] videoSizes, int viewWidth, int viewHeight, int sensorRotation, int deviceRotation)
      Select a set of camera output sizes
      android.graphics.Matrix getViewTransformMatrix​(int imageWidth, int imageHeight, int viewWidth, int viewHeight, int sensorOrientation, int deviceRotation)
      Get matrix to transform a texture view with camera preview to upright orientation and to correct its aspect ratio
      void setMinImageArea​(int minImageArea)
      Set minimum area (width x height in pixels) of images the camera should collect
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • CameraPreviewHelper

        public CameraPreviewHelper()
    • Method Detail

      • getInstance

        public static CameraPreviewHelper getInstance()
        Returns:
        Singleton instance of `CameraPreviewHelper`
        Since:
        2.4.0
      • getMinImageArea

        public int getMinImageArea()
        Returns:
        Minimum area (width x height in pixels) of images collected by the camera
        Since:
        2.5.0
      • setMinImageArea

        public void setMinImageArea​(int minImageArea)
        Set minimum area (width x height in pixels) of images the camera should collect
        Parameters:
        minImageArea - Area (width x height in pixels)
        Since:
        2.5.0
      • getViewTransformMatrix

        public android.graphics.Matrix getViewTransformMatrix​(int imageWidth,
                                                              int imageHeight,
                                                              int viewWidth,
                                                              int viewHeight,
                                                              int sensorOrientation,
                                                              int deviceRotation)
        Get matrix to transform a texture view with camera preview to upright orientation and to correct its aspect ratio
        Parameters:
        imageWidth - Camera image width
        imageHeight - Camera image height
        viewWidth - Width of the view containing the camera preview texture
        viewHeight - Height of the view containing the camera preview texture
        sensorOrientation - Camera sensor orientation relative to the device held upright
        deviceRotation - Rotation of the device
        Returns:
        Matrix
        Since:
        2.4.0
      • getCorrectedTextureSize

        public android.util.Size getCorrectedTextureSize​(int imageWidth,
                                                         int imageHeight,
                                                         int viewWidth,
                                                         int viewHeight,
                                                         int sensorOrientation,
                                                         int deviceRotation)
        Get camera preview texture size corrected to match the device and camera sensor orientation
        Parameters:
        imageWidth - Width of the image obtained from the camera
        imageHeight - Height of the image obtained from the camera
        viewWidth - Width of the texture containing the camera preview
        viewHeight - Height of the texture containing the camera preview
        sensorOrientation - Camera sensor orientation
        deviceRotation - Device rotation
        Returns:
        Size
        Since:
        2.4.0
      • getOutputSizes

        public android.util.Size[] getOutputSizes​(android.util.Size[] previewSizes,
                                                  android.util.Size[] imageReaderSizes,
                                                  android.util.Size[] videoSizes,
                                                  int viewWidth,
                                                  int viewHeight,
                                                  int sensorRotation,
                                                  int deviceRotation)
        Select a set of camera output sizes
        Parameters:
        previewSizes - Preview size candidates
        imageReaderSizes - Image reader size candidates
        videoSizes - Video size candidates
        viewWidth - Width of the view containing the camera preview
        viewHeight - Height of the view containing the camera preview
        sensorRotation - Camera sensor rotation in degrees
        deviceRotation - Device rotation
        Returns:
        Set of output sizes best matching the view size
        Since:
        2.4.0