以人像模式拍摄的照片以风景模式显示

时间:2018-10-17 13:48:32

标签: android

我正在尝试开发照相机视图,并使用这两种方法在onSurfaceChanged中设置照相机参数 拍摄的画面是在风景mode.askdnlakncjkcxjkbzjkcxbzjxcbkjzdncjasndjcnadsjknajdnjansdjandueiyqweufwieufwefnjdfnsjdfnjsdnfjdnfjdnfjdfnjdfnjdnfjdfnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnn

告诉我我在这里做错了。 我正在拍照并在其他活动中显示它。

   /**
 *  Display orientation for Camera is Set so that the view is Rotated when device rotates
 *
 * @param activity
 *          Activity Context
 * @param cameraId
 *          Camera type Front or Back{@link CameraInfo}
 * @param camera
 *         Camera instance
 * */
private void setCameraDisplayOrientation(Activity activity,
                                         int cameraId, android.hardware.Camera camera) {
    android.hardware.Camera.CameraInfo info =
            new android.hardware.Camera.CameraInfo();
    android.hardware.Camera.getCameraInfo(cameraId, info);
    int rotation = activity.getWindowManager().getDefaultDisplay()
            .getRotation();

    int degrees = 0;
    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;
    }

    int result;
    if (info.facing == Camera.CameraInfo.CAMERA_FACING_FRONT) {
        result = (info.orientation + degrees) % 360;
        result = (360 - result) % 360;  // compensate the mirror
    } else {  // back-facing
        result = (info.orientation - degrees + 360) % 360;
    }
    camera.setDisplayOrientation(result);
}


/**
 *  Calculate picture Rotation
 *
 * @param activity
 *          Activity Context
 * @param cameraId
 *          Camera type Front or Back{@link CameraInfo}
 * @param camera
 *         Camera instance
 *
 * @return Rotation require For image depending upon the orientation
 * */
private int calculateCameraPictureRotation(Activity activity, Camera camera, int cameraId) {
    int orientation = activity.getWindowManager().getDefaultDisplay()
            .getRotation();

    int degrees = 0;
    switch (orientation) {
        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;
    }

    android.hardware.Camera.CameraInfo info =
            new android.hardware.Camera.CameraInfo();
    android.hardware.Camera.getCameraInfo(cameraId, info);
    orientation = (degrees + 45) / 90 * 90;
    int rotation = 0;
    if (info.facing == CameraInfo.CAMERA_FACING_FRONT) {
        rotation = (info.orientation - orientation + 360) % 360;
    } else {  // back-facing camera
        rotation = (info.orientation + orientation) % 360;
    }
    return rotation ;

}

0 个答案:

没有答案