我需要将我的相机屏幕顺时针和逆时针旋转 90、180、270、360 角度,用于前后摄像头。我在 SurfaceView 上应用了一个代码块。这里我提供代码:
public void surfaceChanged(SurfaceHolder holder, int format, int width,
int height) {
// Set camera preview size,orientation,rotation using parameters
if (camera != null) {
if (Build.VERSION.SDK_INT >= 8) {
android.hardware.Camera.CameraInfo info = new android.hardware.Camera.CameraInfo();
android.hardware.Camera.getCameraInfo(camId, info);
int rotation = 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);
}
Camera.Parameters parameters = camera.getParameters();
camera.setParameters(parameters);
camera.startPreview();
}
}
如果有人能告诉我如何在我的应用程序中使用内置相机功能,那么也欢迎。