首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >android版本10使用camera2接口采集时图像朝向问题

android版本10使用camera2接口采集时图像朝向问题
EN

Stack Overflow用户
提问于 2020-02-19 18:25:46
回答 2查看 715关注 0票数 1

我已经更新了我的相机功能,从相机到camera2接口。

当我用前置摄像头捕捉图像并在imageview中显示时。图像的方向已更改。然后,我使用此代码更改图像的方向。

代码语言:javascript
复制
int jpegOrientation =
                (ORIENTATIONS.get(rotation) + characteristics.get(CameraCharacteristics.SENSOR_ORIENTATION) + 270) % 360;
capturebuilder.set(CaptureRequest.JPEG_ORIENTATION, jpegOrientation);

上面的代码适用于android版本(即版本5,9),我已经测试过了。当我在Android版本10中运行相同的代码时,它不能工作。下图所示

请,任何人都可以帮助我解决这个问题

EN

回答 2

Stack Overflow用户

发布于 2020-02-19 19:21:00

代码语言:javascript
复制
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;
 }

要了解更多细节,请阅读以下帖子:

票数 1
EN

Stack Overflow用户

发布于 2020-02-19 19:10:24

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/60298127

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档