[英]What is the Camera2 API Equivalent of setDisplayOrientation()?
With android.hardware.Camera
, in order to have the camera output appropriately track the device movement, we need to hook up an OrientationEventListener
to the setDisplayOrientation()
method on Camera
. 使用
android.hardware.Camera
,为了使摄像机输出适当地跟踪设备移动,我们需要将OrientationEventListener
到Camera
上的setDisplayOrientation()
方法。 That way, as the user twists the device around, we can keep what is "up" on the camera preview in sync with what is "up" in the real world. 这样,当用户扭转设备时,我们可以保持相机预览中的“向上”与现实世界中的“向上”同步。 This is particularly true for rotating the device around the Y axis (ie, flipping from landscape to reverse-landscape or back).
对于围绕Y轴旋转设备(即,从横向翻转到反向横向或向后),尤其如此。
For most orientation changes, the android.hardware.camera2
API seems to "just work". 对于大多数方向更改,
android.hardware.camera2
API似乎“正常工作”。 However, for that Y-axis rotation (landscape -> reverse-landscape or vice versa), the camera preview winds up being inverted. 但是,对于Y轴旋转(横向 - >反向横向或反向横向),相机预览会被反转。
What is the equivalent of calling setDisplayOrientation()
on Camera
for the Camera2 API, so we can handle this scenario? 在
Camera
为Camera2 API调用setDisplayOrientation()
相当于什么,所以我们可以处理这种情况?
As you've noticed, this is supposed to "just work" for SurfaceView
on the camera2 API. 正如您所注意到的那样,这应该在camera2 API上为
SurfaceView
“正常工作”。
As such, there's no equivalent of setDisplayOrientation()
. 因此,没有
setDisplayOrientation()
等价物。
We haven't heard of this issue before now, so a few questions: 我们之前没有听说过这个问题,所以有几个问题:
使用此CaptureRequest JPEG_ORIENTATION设置显示方向
captureBuilder.set(CaptureRequest.JPEG_ORIENTATION, 90)
use the formula below to get device rotation. 使用下面的公式来获取设备旋转。
private int getOrientation(int rotation) {
return (ORIENTATIONS.get(rotation) + mSensorOrientation + 270) % 360;
}
SensorOrientation is a field assigned from SensorOrientation是从中分配的字段
characteristics.get(CameraCharacteristics.SENSOR_ORIENTATION)
Solution suggested by google engineer: yaraki 谷歌工程师建议的解决方案:yaraki
https://github.com/googlesamples/android-Camera2Basic/issues/24 https://github.com/googlesamples/android-Camera2Basic/issues/24
There is none. 空无一人。
It does not "just work" if display orientation is swapped compared to sensor orientation (on most devices this is the case in portrait mode) because you have to set an aspect ratio < 1 for your preview surface that camera2 cannot map to a fitting output size. 如果交换显示方向与传感器方向相比,它不会“正常工作”(在大多数设备上都是纵向模式),因为您必须为预览表面设置宽高比<1,即相机2无法映射到适合的输出尺寸。 Solution:
解:
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.