Camera2的API,对象大小,的getHeight方法返回宽度和返回的getWidth高度

问题描述 投票:0回答:1

这没有任何意义,我为我的标题说。应该返回宽度,则返回1920年应返回高度的方法,该方法返回1080我做错什么了吗?

我的相机活动锁定在肖像模式。我的手机是三星注4.由于我的手机是在肖像模式和锁定在那个方向,我的身高应该是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];
    }

}
android android-camera android-camera2
1个回答
1
投票

您可以旋转的质感,但即使在纵向模式下相机硬件仍在生产相同的图像。见Why camera2 supported preview size width always bigger than height?了解更多详情。

如果您使用MediaRecorder制作的视频,或使用ImageReader的捕捉上飞的预览图像,他们也将抵达由摄像头硬件决定的方向。为适合您的设备的方向,你必须明确地旋转它们。

© www.soinside.com 2019 - 2024. All rights reserved.