我正在研究Camera应用程序
但是在setCameraOrientation
中,当我尝试进行显示旋转时,我总是在rotation
中得到0
/**If you want to make the camera image show in the same orientation as the display, you can use the following code.
*/
public static 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);
}
在onSurfaceChanged
答案 0 :(得分:0)
尝试
Display display = ((WindowManager)getSystemService(WINDOW_SERVICE)).getDefaultDisplay();
if(display.getRotation() == Surface.ROTATION_0)
if(display.getRotation() == Surface.ROTATION_90)
if(display.getRotation() == Surface.ROTATION_180)
if(display.getRotation() == Surface.ROTATION_270)
答案 1 :(得分:0)
如果关闭自动旋转功能,这会在我的手机(三星J3 Prime)中发生。