Search in sources :

Example 6 with CameraInfo

use of android.hardware.Camera.CameraInfo in project libstreaming by fyhertz.

the class VideoStream method setCamera.

/**
	 * Sets the camera that will be used to capture video.
	 * You can call this method at any time and changes will take effect next time you start the stream.
	 * @param camera Can be either CameraInfo.CAMERA_FACING_BACK or CameraInfo.CAMERA_FACING_FRONT
	 */
public void setCamera(int camera) {
    CameraInfo cameraInfo = new CameraInfo();
    int numberOfCameras = Camera.getNumberOfCameras();
    for (int i = 0; i < numberOfCameras; i++) {
        Camera.getCameraInfo(i, cameraInfo);
        if (cameraInfo.facing == camera) {
            mCameraId = i;
            break;
        }
    }
}
Also used : CameraInfo(android.hardware.Camera.CameraInfo) SuppressLint(android.annotation.SuppressLint)

Example 7 with CameraInfo

use of android.hardware.Camera.CameraInfo in project android-vision by googlesamples.

the class CameraSource method setRotation.

/**
     * Calculates the correct rotation for the given camera id and sets the rotation in the
     * parameters.  It also sets the camera's display orientation and rotation.
     *
     * @param parameters the camera parameters for which to set the rotation
     * @param cameraId   the camera id to set rotation based on
     */
private void setRotation(Camera camera, Camera.Parameters parameters, int cameraId) {
    WindowManager windowManager = (WindowManager) mContext.getSystemService(Context.WINDOW_SERVICE);
    int degrees = 0;
    int rotation = windowManager.getDefaultDisplay().getRotation();
    switch(rotation) {
        case Surface.ROTATION_0:
            degrees = 0;
            break;
        case Surface.ROTATION_90:
            degrees = 90;
            break;
        case Surface.ROTATION_180:
            degrees = 180;
            break;
        case Surface.ROTATION_270:
            degrees = 270;
            break;
        default:
            Log.e(TAG, "Bad rotation value: " + rotation);
    }
    CameraInfo cameraInfo = new CameraInfo();
    Camera.getCameraInfo(cameraId, cameraInfo);
    int angle;
    int displayAngle;
    if (cameraInfo.facing == Camera.CameraInfo.CAMERA_FACING_FRONT) {
        angle = (cameraInfo.orientation + degrees) % 360;
        // compensate for it being mirrored
        displayAngle = (360 - angle) % 360;
    } else {
        // back-facing
        angle = (cameraInfo.orientation - degrees + 360) % 360;
        displayAngle = angle;
    }
    // This corresponds to the rotation constants in {@link Frame}.
    mRotation = angle / 90;
    camera.setDisplayOrientation(displayAngle);
    parameters.setRotation(angle);
}
Also used : CameraInfo(android.hardware.Camera.CameraInfo) SuppressLint(android.annotation.SuppressLint) WindowManager(android.view.WindowManager)

Example 8 with CameraInfo

use of android.hardware.Camera.CameraInfo in project XobotOS by xamarin.

the class CamcorderProfile method hasProfile.

/**
     * Returns true if camcorder profile exists for the first back-facing
     * camera at the given quality level.
     * @param quality the target quality level for the camcorder profile
     */
public static boolean hasProfile(int quality) {
    int numberOfCameras = Camera.getNumberOfCameras();
    CameraInfo cameraInfo = new CameraInfo();
    for (int i = 0; i < numberOfCameras; i++) {
        Camera.getCameraInfo(i, cameraInfo);
        if (cameraInfo.facing == CameraInfo.CAMERA_FACING_BACK) {
            return hasProfile(i, quality);
        }
    }
    return false;
}
Also used : CameraInfo(android.hardware.Camera.CameraInfo)

Example 9 with CameraInfo

use of android.hardware.Camera.CameraInfo in project android_frameworks_base by DirtyUnicorns.

the class CameraProfile method getJpegEncodingQualityParameter.

/**
     * Returns a pre-defined still image capture (jpeg) quality level
     * used for the given quality level in the Camera application for
     * the first back-facing camera on the device. If the device has no
     * back-facing camera, this returns 0.
     *
     * @param quality The target quality level
     */
public static int getJpegEncodingQualityParameter(int quality) {
    int numberOfCameras = Camera.getNumberOfCameras();
    CameraInfo cameraInfo = new CameraInfo();
    for (int i = 0; i < numberOfCameras; i++) {
        Camera.getCameraInfo(i, cameraInfo);
        if (cameraInfo.facing == CameraInfo.CAMERA_FACING_BACK) {
            return getJpegEncodingQualityParameter(i, quality);
        }
    }
    return 0;
}
Also used : CameraInfo(android.hardware.Camera.CameraInfo)

Example 10 with CameraInfo

use of android.hardware.Camera.CameraInfo in project android_frameworks_base by AOSPA.

the class CamcorderProfile method get.

/**
     * Returns the camcorder profile for the first back-facing camera on the
     * device at the given quality level. If the device has no back-facing
     * camera, this returns null.
     * @param quality the target quality level for the camcorder profile
     * @see #get(int, int)
     */
public static CamcorderProfile get(int quality) {
    int numberOfCameras = Camera.getNumberOfCameras();
    CameraInfo cameraInfo = new CameraInfo();
    for (int i = 0; i < numberOfCameras; i++) {
        Camera.getCameraInfo(i, cameraInfo);
        if (cameraInfo.facing == CameraInfo.CAMERA_FACING_BACK) {
            return get(i, quality);
        }
    }
    return null;
}
Also used : CameraInfo(android.hardware.Camera.CameraInfo)

Aggregations

CameraInfo (android.hardware.Camera.CameraInfo)56 Camera (android.hardware.Camera)6 CameraCharacteristics (android.hardware.camera2.CameraCharacteristics)5 ServiceSpecificException (android.os.ServiceSpecificException)5 SuppressLint (android.annotation.SuppressLint)3 WindowManager (android.view.WindowManager)2 IOException (java.io.IOException)2 TargetApi (android.annotation.TargetApi)1 Intent (android.content.Intent)1 Bitmap (android.graphics.Bitmap)1 Face (android.hardware.Camera.Face)1 FaceDetectionListener (android.hardware.Camera.FaceDetectionListener)1 MediaRecorder (android.media.MediaRecorder)1 Uri (android.net.Uri)1 Bundle (android.os.Bundle)1 NonNull (android.support.annotation.NonNull)1 Pair (android.util.Pair)1 LayoutInflater (android.view.LayoutInflater)1 ViewGroup (android.view.ViewGroup)1 AppDataDirGuesser (com.google.testing.littlemock.AppDataDirGuesser)1