android - Android - 纵向模式下的 Google 示例 HdrViewFinder
问题描述
有人可以帮我解决以下代码。我想HdrViewFinder
从谷歌样本(https://github.com/googlesamples/android-HdrViewfinder)转换项目,以便它也可以在纵向模式下工作。但该项目仅适用于横向模式。在纵向模式下,相机预览会失真。
所以,这是我从 HdrViewfinderActivity.java 类中提取的方法,我认为它负责将整个视图设置为横向:
/**
* Configure the surfaceview and RS processing.
*/
private void configureSurfaces() {
// Find a good size for output - largest 16:9 aspect ratio that's less than 720p
final int MAX_WIDTH = 1280;
final float TARGET_ASPECT = 16.f / 9.f;
final float ASPECT_TOLERANCE = 0.1f;
StreamConfigurationMap configs =
mCameraInfo.get(CameraCharacteristics.SCALER_STREAM_CONFIGURATION_MAP);
if (configs == null) {
throw new RuntimeException("Cannot get available picture/preview sizes.");
}
Size[] outputSizes = configs.getOutputSizes(SurfaceHolder.class);
Size outputSize = outputSizes[0];
float outputAspect = (float) outputSize.getWidth() / outputSize.getHeight();
for (Size candidateSize : outputSizes) {
if (candidateSize.getWidth() > MAX_WIDTH) continue;
float candidateAspect = (float) candidateSize.getWidth() / candidateSize.getHeight();
boolean goodCandidateAspect =
Math.abs(candidateAspect - TARGET_ASPECT) < ASPECT_TOLERANCE;
boolean goodOutputAspect =
Math.abs(outputAspect - TARGET_ASPECT) < ASPECT_TOLERANCE;
if ((goodCandidateAspect && !goodOutputAspect) ||
candidateSize.getWidth() > outputSize.getWidth()) {
outputSize = candidateSize;
outputAspect = candidateAspect;
}
}
Log.i(TAG, "Resolution chosen: " + outputSize);
// Configure processing
mProcessor = new ViewfinderProcessor(mRS, outputSize);
setupProcessor();
// Configure the output view - this will fire surfaceChanged
mPreviewView.setAspectRatio(outputAspect);
mPreviewView.getHolder().setFixedSize(outputSize.getWidth(), outputSize.getHeight());
}
我如何更改此方法以使其在纵向模式下也可以使用?我需要改变什么?仅将screenOrientation
清单文件中的属性设置为portrait
没有帮助。我发现16:9
用于全横向模式和9:16
用于全纵向模式。所以,我MAX_WIDTH
改为720
和TARGET_ASPECT
。9.f/16.f
但这也无济于事。
有人可以提供解决方案吗?
解决方案
我有一个实验叉子,通过从 SurfaceView 切换到 TextureView 来实现这一点。
在带有Android Pie的 Sony G8441 aka Xperia XZ1 Compact 上测试
推荐阅读
- r - R for 循环结果
- excel - 如何从 Excel 值更改日期和时间格式?
- winapi - winapi - AppendMenu - 文本布局
- sql-server - 使用 max(date) 返回单个日期
- javascript - chrome 不支持 ShowModelDialog
- jenkins - 仅归档 katalon jenkins 作业中的最新 .png 文件
- matlab - 如何在地块上使用刺作为刻度?
- python - 传递给我的自定义模块时 var 类型的 Ansible 错误
- flutter - 如何在颤动的图像中插入可点击点?
- java - 连接spring boot应用程序和google Cloud SQL的推荐方式是什么?