[英]Sensor orientation doesn't fit device orientation
I have an application which until now worked only in landscape mode.我有一个应用程序,到现在为止只能在横向模式下工作。 Here is the code:
这是代码:
AndroidManifest.xml AndroidManifest.xml
<activity
android:name=".MainActivity"
android:exported="true"
android:screenOrientation="landscape"
tools:ignore="LockedOrientationActivity">
CameraHelper.java CameraHelper.java
private void bindCamera(@NonNull ProcessCameraProvider cameraProvider) {
Log.d(TAG, "Binding camera");
CameraSelector cameraSelector = new CameraSelector.Builder()
.requireLensFacing(CameraSelector.LENS_FACING_BACK)
.build();
// Image analysis settings
ImageAnalysis.Builder imageAnalysisBuilder = new ImageAnalysis.Builder();
ImageAnalysis imageAnalysis = imageAnalysisBuilder
.setImageQueueDepth(1)
.setTargetResolution(new Size(1280, 720))
.setBackpressureStrategy(ImageAnalysis.STRATEGY_KEEP_ONLY_LATEST)
.build();
imageAnalysis.setAnalyzer(analyzerExecutor, imageAnalyzer);
var captureBuilder = new ImageCapture.Builder();
captureBuilder.setTargetRotation(Surface.ROTATION_90).
setCaptureMode(ImageCapture.CAPTURE_MODE_MINIMIZE_LATENCY).
setTargetResolution(new Size(4032, 3024)).
setJpegQuality(Constants.JPEG_QUALITY).
setFlashMode(ImageCapture.FLASH_MODE_OFF);
var ext = new Camera2Interop.Extender<>(captureBuilder);
ext.setCaptureRequestOption(CaptureRequest.CONTROL_CAPTURE_INTENT,
CaptureRequest.CONTROL_CAPTURE_INTENT_MOTION_TRACKING);
imageCapture = captureBuilder.build();
try {
cameraProvider.unbindAll();
if (lifecycleOwner.getLifecycle().getCurrentState() != DESTROYED) {
this.camera = cameraProvider.bindToLifecycle(lifecycleOwner,
cameraSelector,
imageCapture,
imageAnalysis);
}
} catch (Exception e) {
Log.e(TAG, "Camera binding failed", e);
MainActivity.instance.snackbar.showError("Camera binding failed", e);
}
}
Now, i would like the application to work only in portrait mode.现在,我希望该应用程序只能在纵向模式下工作。 Steps i did:
我做的步骤:
I tried treading from here and if i understand correctly i need to rotate camera sensor.我试着从这里开始,如果我理解正确的话,我需要旋转相机传感器。
Please advise me what changes i need to do in my code to get the portrait mode 720x1280 orientation.请告诉我我需要在我的代码中做哪些更改才能获得纵向模式 720x1280 方向。
Thanks!谢谢!
I managed to solve my problem, apparently when i tried to change Size to Size(720,1280) - this created camera with 1280x720 resolution, but it's really an image of size width=720 and height=1280, so it was confusing, i just need than to flip the image i got.我设法解决了我的问题,显然是在我尝试将 Size 更改为 Size(720,1280) 时 - 这创建了分辨率为 1280x720 的相机,但它实际上是一个尺寸为 width=720 和 height=1280 的图像,所以它很混乱,我只需要翻转我得到的图像。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.