正如我在标题中所说,这对我来说没有任何意义。应该返回宽度的方法返回1920,应该返回高度的方法返回1080。我做错了吗?
我的相机活动被锁定为人像模式。我的手机是Samsung Note4。由于我的手机处于纵向模式并锁定在该方向,因此我的高度应该为1920,宽度应该为1080,但是当我不将相机活动锁定为纵向模式时,它仍然会返回错误值,但将其设置为横向模式时,高度为1080,宽度为1920。
我的代码:
mPreviewSize =
chooseOptimalSize(map.getOutputSizes(SurfaceTexture.class), rotatedWidth,
rotatedHeight);
private static Size chooseOptimalSize(Size[] choices, int width, int
height) {
List<Size> bigEnough = new ArrayList<Size>();
for(Size option : choices) {
Log.d("detectivepikachu","option: h: "+option.getHeight()+" w:
"+option.getWidth());
if(option.getHeight() == option.getWidth() * height / width &&
option.getWidth() >= width && option.getHeight() >=
height) {
bigEnough.add(option);
}
}
if(bigEnough.size() > 0) {
return Collections.min(bigEnough, new CompareSizeByArea());
} else {
return choices[0];
}
}
答案 0 :(得分:1)
您可以旋转纹理,但是即使在纵向模式下,相机硬件仍可以产生相同的图像。有关更多详细信息,请参见 Why camera2 supported preview size width always bigger than height? 。
如果您使用 MediaRecorder 制作视频,或使用 ImageReader 即时捕获预览图像,它们也将按照相机硬件的指示到达。要适应设备的方向,必须显式旋转它们。