get Preview Orientation Degrees - Android Camera

Android examples for Camera:Camera Preview

Description

get Preview Orientation Degrees

Demo Code

/*/*from  w w w.  j  a  va  2  s . c  om*/
 *  Copyright (C) 2012 Simon Robinson
 * 
 *  This file is part of Com-Me.
 * 
 *  Com-Me is free software; you can redistribute it and/or modify it 
 *  under the terms of the GNU Lesser General Public License as 
 *  published by the Free Software Foundation; either version 3 of the 
 *  License, or (at your option) any later version.
 *
 *  Com-Me is distributed in the hope that it will be useful, but WITHOUT 
 *  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY 
 *  or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser General 
 *  Public License for more details.
 *
 *  You should have received a copy of the GNU Lesser General Public
 *  License along with Com-Me.
 *  If not, see <http://www.gnu.org/licenses/>.
 */
//package com.java2s;

import android.util.Log;

public class Main {
    private static final String LOG_TAG = "CameraUtilities";

    public static int getPreviewOrientationDegrees(
            int screenOrientationDegrees, Integer cameraOrientationDegrees,
            boolean usingFrontCamera) {

        int previewOrientationDegrees = 0;

        if (cameraOrientationDegrees != null) {
            if (usingFrontCamera) { // compensate for the mirror of the front camera
                previewOrientationDegrees = (cameraOrientationDegrees + screenOrientationDegrees) % 360;
                previewOrientationDegrees = (360 - previewOrientationDegrees) % 360;
            } else { // back-facing
                previewOrientationDegrees = (cameraOrientationDegrees
                        - screenOrientationDegrees + 360) % 360;
            }
        } else {
            // TODO: can we detect camera orientation somehow?
            Log.d(LOG_TAG,
                    "Unable to detect camera orientation - setting to 0");
            previewOrientationDegrees = 0;// (90 - screenOrientationDegrees + 360) % 360;
        }

        return previewOrientationDegrees;
    }
}

Related Tutorials