Class CameraUtil

  • All Implemented Interfaces:

    
    public class CameraUtil
    
                        
    • Constructor Detail

      • CameraUtil

        CameraUtil()
    • Method Detail

      • hasCamera

         static boolean hasCamera(Context context)

        return true if device has a camera.

      • getCameraDisplayRotation

         static int getCameraDisplayRotation(Context context, int cameraId)

        An implementation of the code in the docs of setDisplayOrientation (just returning the degrees instead of setting them directly). This returns the degrees the preview frame needs to get rotated to be the same as actually seen.

        Parameters:
        context - the context
        cameraId - the camera id to get the rotation from
        Returns:

        the degrees the image has to be rotated to be the same as actually seen.

      • getCameraRotation

         static int getCameraRotation(Context context, int cameraId)

        An implementation of the code in the docs of setRotation (just returning the degrees instead of setting them directly).

        Returns the camera rotation which needs to be compensated with setRotation

        Parameters:
        context - the context
        cameraId - the camera id to get the rotation from
        Returns:

        the degrees the camera rotation needs to be set, to retrieve correct frames

      • getCameraDisplayRotation

         static int getCameraDisplayRotation(Context context, CameraCharacteristics cameraCharacteristics)

        Get the rotation of camera relative to the display orientation

        Parameters:
        context - the context
        cameraCharacteristics - the camera characteristics of the camera to check
        Returns:

        the rotation of camera relative to the display orientation

      • getDisplayRotationDegrees

         static int getDisplayRotationDegrees(Context context)
        Parameters:
        context - the context
        Returns:

        the rotation of the display (relative to the natural orientation) in degrees

      • getBiggestFittingPreviewSize

         static CameraSize getBiggestFittingPreviewSize(List<CameraSize> availableCameraPreviewSizes, int maxRequestedCameraPreviewWidth, int maxRequestedCameraPreviewHeight)

        This helper method can be called to select camera preview size. It goes over the list of the supported preview sizes and selects the maximum one which fits. It was previously much simpler, but required a rework with [SDKY-122], because it didn't account for availableCameraPreviewSizes containing a size (i.e. 1280x720) and its sides-swapped counterpart size (i.e. 720x1280). For this case, the position within availableCameraPreviewSizes would determine which size was returned (i.e. if 1280x720 was return 720x1280, even though 1280x720 would have been correct). Because we have no way of knowing the orientation the camera considers native, we're guessing that the camera provides a greater number of sizes in its native resolution and then decide based on this which CameraPreviewSize should be correct. Potentially there are some special cases that are not considered, but also have not yet been observed, i.e.: - CameraPreviewSizes being natively only square (instead of portrait/landscape) - Multiple results with the same resolution in the same format (i.e. 2x 1280x720) - CameraPreviewSize absolutely being unable to return any size

        Parameters:
        availableCameraPreviewSizes - - the supported sizes
        maxRequestedCameraPreviewWidth - - the max width
        maxRequestedCameraPreviewHeight - - the max height
        Returns:

        the biggest size that fits in the given max values

      • getBiggestFittingPreviewFps

         static CameraFeatures.FpsRange getBiggestFittingPreviewFps(Array<CameraFeatures.FpsRange> supportedFps, int minFps, int maxFps)

        This helper method can be called to select camera preview FPS. It goes over the list of the supported preview FPS ranges and selects the maximum one which fits.

        Parameters:
        supportedFps - the supported FPS ranges of the device
        minFps - the preferred min preview fps
        maxFps - the preferred max preview fps
        Returns:

        the biggest size that fits in the given min max values

      • getBestFittingPictureSize

         static CameraSize getBestFittingPictureSize(List<CameraSize> pictureSizes, int preferredPictureWidth, int preferredPictureHeight, List<CameraUtil.AspectRatio> preferredAspectRatios)

        Determines the best fitting Picture size for the given parameters. There are two possible scenarios:

        If the preferred sizes are not 0, the lowest available resolution greater than the sizes is returned. If there is no resolution found greater than the preferred sizes, the highest resolution in 16:9, 5:3 or 16:10 is returned. If there is no resolution with these aspect ratios, the highest resolution in any aspect ratio is returned.

        If the preferred sizes are 0, the highest available resolution in the preferredAspectRatio is returned. If none is found, the highest resolution in any aspect ratio is returned.

        Parameters:
        pictureSizes - the supported sizes
        preferredPictureWidth - the preferred (minimum) width of the picture
        preferredPictureHeight - the preferred (minimum) height of the picture
        preferredAspectRatios - a list of the preferred aspect ratios
        Returns:

        The smallest size in the aspect ratio that is bigger than the provided preferred size, or a fallback (see above)