Camera.Parameters.SetRotation(Int32) 方法
定義
重要
部分資訊涉及發行前產品,在發行之前可能會有大幅修改。 Microsoft 對此處提供的資訊,不做任何明確或隱含的瑕疵擔保。
警告
deprecated
將順時針旋轉角度設定為相對於相機方向的度數。
[Android.Runtime.Register("setRotation", "(I)V", "GetSetRotation_IHandler")]
[System.Obsolete("deprecated")]
public virtual void SetRotation(int rotation);
[<Android.Runtime.Register("setRotation", "(I)V", "GetSetRotation_IHandler")>]
[<System.Obsolete("deprecated")>]
abstract member SetRotation : int -> unit
override this.SetRotation : int -> unit
參數
- rotation
- Int32
相對於相機方向的旋轉角度(度數)。 旋轉只能是0、90、180或270。
- 屬性
例外狀況
如果旋轉值不成立。
備註
將順時針旋轉角度設定為相對於相機方向的度數。 這會影響從 JPEG PictureCallback回傳的照片。 相機驅動程式可在 EXIF 標頭設定方向,且不旋轉影像。 或者驅動程式會旋轉圖片和 EXIF 縮圖。 如果 JPEG 圖片被旋轉,EXIF 標頭的方向會遺失或 1(列 #0 在上,欄 #0 在左側)。
如果應用程式想將圖片旋轉以符合使用者所見的方向,應用程式應該使用 android.view.OrientationEventListener 和 android.hardware.Camera.CameraInfo。 OrientationEventListener 的值是相對於裝置的自然方向。 CameraInfo.orientation 是相機方向與自然裝置方向之間的角度。 兩者的總和就是後向攝影機的旋轉角度。 兩者的差異在於前置攝影機的旋轉角度。 請注意,前置相機的 JPEG 圖片不像預覽顯示那樣是鏡像。
例如,假設裝置的自然方向是直向。 裝置順時針旋轉270度,因此裝置方向為270度。 假設一個背面相機感測器安裝在橫向畫面中,且相機感測器的上半部自然對齊於顯示器的右側邊緣。 所以攝影機的朝向是90度。 旋轉應設為 0(270 + 90)。
參考代碼如下。
public void onOrientationChanged(int orientation) {
if (orientation == ORIENTATION_UNKNOWN) return;
android.hardware.Camera.CameraInfo info =
new android.hardware.Camera.CameraInfo();
android.hardware.Camera.getCameraInfo(cameraId, info);
orientation = (orientation + 45) / 90 * 90;
int rotation = 0;
if (info.facing == CameraInfo.CAMERA_FACING_FRONT) {
rotation = (info.orientation - orientation + 360) % 360;
} else { // back-facing camera
rotation = (info.orientation + orientation) % 360;
}
mParameters.setRotation(rotation);
}
Java 文件 android.hardware.Camera.Parameters.setRotation(int)。
本頁部分內容為基於 Open Source Project 所創建與分享的作品,並依授權條款所描述的使用進行修改。
適用於
另請參閱
- OrientationEventListener
- <xref:Android.Hardware.Camera.GetCameraInfo(System.Int32%2c+Android.Hardware.Camera.CameraInfo)>