Shr*_*jan 1 android android-layout android-camera
在我的Android相机应用程序中,我已将应用程序清单设置为Portrait.但是当我正在运行我的相机应用程序时,相机预览显示为横向而不是纵向.
我不知道问题出在哪里,但我需要帮助.我想将我的相机预览设置为普通相机预览.并将应用程序设置为纵向.
有什么解决方案吗?
Camera.setDisplayOrientation(90); 只要它保持纵向,就应该做到这一点.
另外,根据文件:
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);
}
Run Code Online (Sandbox Code Playgroud)
此代码段可用于根据手机的方向设置摄像机的方向.
| 归档时间: |
|
| 查看次数: |
5143 次 |
| 最近记录: |