我已经更新了我的相机功能,从相机到camera2接口。
当我用前置摄像头捕捉图像并在imageview中显示时。图像的方向已更改。然后,我使用此代码更改图像的方向。
int jpegOrientation =
(ORIENTATIONS.get(rotation) + characteristics.get(CameraCharacteristics.SENSOR_ORIENTATION) + 270) % 360;
capturebuilder.set(CaptureRequest.JPEG_ORIENTATION, jpegOrientation);上面的代码适用于android版本(即版本5,9),我已经测试过了。当我在Android版本10中运行相同的代码时,它不能工作。下图所示

请,任何人都可以帮助我解决这个问题
发布于 2020-02-19 19:21:00
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;
}要了解更多细节,请阅读以下帖子:
发布于 2020-02-19 19:10:24
https://stackoverflow.com/questions/60298127
复制相似问题