加入setDisplayOrientation我已經編碼只肖像模式的應用程序:
注意。
camera.setDisplayOrientation(90);
將相機旋轉到90度,這可能會導致不適合定位於Android的 一些設備爲了獲取所有Android設備的正確預覽使用下面的代碼,在審閱開發者網站。
下面,你必須把你的活動,cameraId =後面是0和前置攝像頭爲1
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;
//int currentapiVersion = android.os.Build.VERSION.SDK_INT;
// do something for phones running an SDK before lollipop
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);
}
這是如何設置setDisplayOrientation相機這將完全適用於所有的Android設備。
僅供參考我的三星YP-G70(Galaxy player 5.0)一直處於橫向模式。 – cliff2310
http://stackoverflow.com/questions/8475532/android-camera-in-view-with-buttons-and-text-over 希望這將幫助你.. –