Camera.SetDisplayOrientation(Int32) 方法
定義
重要
部分資訊涉及發行前產品,在發行之前可能會有大幅修改。 Microsoft 對此處提供的資訊,不做任何明確或隱含的瑕疵擔保。
警告
deprecated
將預覽畫面的順時針旋轉設定為度數。
[Android.Runtime.Register("setDisplayOrientation", "(I)V", "")]
[System.Obsolete("deprecated")]
public void SetDisplayOrientation(int degrees);
[<Android.Runtime.Register("setDisplayOrientation", "(I)V", "")>]
[<System.Obsolete("deprecated")>]
member this.SetDisplayOrientation : int -> unit
參數
- degrees
- Int32
圖片順時針旋轉的角度。 有效值為 0、90、180 和 270。
- 屬性
備註
將預覽畫面的順時針旋轉設定為度數。 這會影響預覽畫面和快照後顯示的圖片。 此方法適用於直式模式應用。 請注意,前置攝影機的預覽顯示在旋轉前會水平翻轉,也就是影像沿相機感測器的中央垂直軸反射。 使用者可以把自己看成照鏡子。
這不影響傳送進 PreviewCallback#onPreviewFrame來的位元組陣列順序、JPEG 圖片或錄影影片。 預覽期間不允許呼叫此方法。
如果你想讓相機影像以與顯示器相同的方向顯示,可以使用以下程式碼。
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);
}
從 API 層級 14 開始,當預覽啟動時即可呼叫此方法。
<b>注意: </b>在 API 等級 24 之前,預設的方向值為 0。 從 API 層級 24 開始,預設方向將是強制橫向模式下的應用程式會有正確的預覽方向,預設可能是 0 或 180。 以直式模式運作或允許改變方向的應用程式,仍必須在每次方向變更後呼叫此方法,以確保所有情況下預覽顯示正確。
Java 文件 android.hardware.Camera.setDisplayOrientation(int)。
本頁部分內容為基於 Open Source Project 所創建與分享的作品,並依授權條款所描述的使用進行修改。