1

我想在保存到SD卡之前鏡像前置攝像頭的圖像。事情是在像索尼Xperia Z5這樣的設備上,鏡像後也會將圖像旋轉90度。 我不能使用ExifInterface來獲取方向,因爲它需要一個文件路徑,在我的情況下我還沒有保存它。前置攝像頭 - 鏡像並在保存前正確旋轉

是否有機會獲得特定設備的方向,以便我可以正確旋轉它們?

預設:

  • Camera2阿比
  • 只有肖像照片
+0

讓你找到了解決辦法,I'm面臨同樣的問題;( – Andrea

回答

1

在你captureBuilder,你有一個參數來設置圖像的 「方向」 是抽放前:CaptureRequest.JPEG_ORIENTATION

Android Developer website say:

JPEG圖像的方向。

以相對於相機的方向 的順時針旋轉角度(以度爲單位),即JPEG圖片需要旋轉的垂直角度爲 。

相機設備可以將此值編碼爲JPEG EXIF標頭 或旋轉圖像數據以匹配此方向。當圖像 數據被旋轉時,縮略圖數據也將被旋轉。

請注意,此方向是相對於由android.sensor.orientation給出的 相機傳感器的方向。

您可以在您CaptureBuilder設置此參數:

//To get the right orientation we must to get it in base of the sensor position. 
mSensorOrientation = getSensorOrientation(); 
captureBuilder.set(CaptureRequest.JPEG_ORIENTATION, mSensorOrientation); 

從CameraCharacteristics,你可以從CameraManager得到讓您的傳感器定位:

public int getSensorOrientation() throws CameraAccessException { 
    return mCameraManager.getCameraCharacteristics(mCameraId).get(
      CameraCharacteristics.SENSOR_ORIENTATION); 
} 

希望它會幫助你!

編輯: 我附加了一種方法,我很久以前就發現了一種方法來獲取圖片的「真實」方向,具體取決於您是否在正面相機,傳感器設備方向和您想要的方向爲你的照片。

public static int sensorToDeviceRotation(boolean mirror, int deviceOrientation, int sensorOrientation) { 

    // Reverse device orientation for front-facing cameras 
    if (mirror) { 
     deviceOrientation = -deviceOrientation; 
    } 
    // Calculate desired JPEG orientation relative to camera orientation to make 
    // the image upright relative to the device orientation 
    return (sensorOrientation + deviceOrientation + 360) % 360; 
} 
+0

日Thnx爲您迴應的事情是,我從不同的設備得到相同的旋轉,他們都是270的前置攝像頭。但是隻有一個設備在向位圖添加鏡像矩陣之後向圖像添加了90度:( – Maxi

+0

檢查最後的編輯,也許它會幫助您 –

+0

您是否修復了它? –

相關問題