簡體   English   中英

在 android 版本 10 中使用 camera2 api 捕獲時出現圖像方向問題

[英]Issue with image orientation when capturing using camera2 api in android version 10

我已將我的相機功能從 Camera 更新為 camera2 api。

當我用前置攝像頭捕獲圖像並將其顯示在 imageview 中時。 圖像的方向發生了變化。 然后我用這個代碼來改變圖像的方向。

int jpegOrientation =
                (ORIENTATIONS.get(rotation) + characteristics.get(CameraCharacteristics.SENSOR_ORIENTATION) + 270) % 360;
capturebuilder.set(CaptureRequest.JPEG_ORIENTATION, jpegOrientation);

上面的代碼適用於我測試過的 android 版本(即版本 5,9)。 當我在 Android 版本 10 中運行相同的代碼時,它不起作用。 下面是圖片在此處輸入圖片說明

請,任何人都可以幫助我解決這個問題

private int getJpegOrientation(CameraCharacteristics c, int deviceOrientation) {
     if (deviceOrientation == android.view.OrientationEventListener.ORIENTATION_UNKNOWN) return 0;
     int sensorOrientation = c.get(CameraCharacteristics.SENSOR_ORIENTATION);

     // Round device orientation to a multiple of 90
     deviceOrientation = (deviceOrientation + 45) / 90 * 90;

     // Reverse device orientation for front-facing cameras
     boolean facingFront = c.get(CameraCharacteristics.LENS_FACING) == CameraCharacteristics.LENS_FACING_FRONT;
     if (facingFront) deviceOrientation = -deviceOrientation;

     // Calculate desired JPEG orientation relative to camera orientation to make
     // the image upright relative to the device orientation
     int jpegOrientation = (sensorOrientation + deviceOrientation + 360) % 360;

     return jpegOrientation;
 }

要了解更多詳細信息,請關注此帖子: https : //medium.com/@kenodoggy/solving-image-rotation-on-android-using-camera2-api-7b3ed3518ab6

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM