相机 2 Api 预览被拉伸

Camera 2 Api preview is stretched

我使用旧相机 api 和相机 2 api,使用 GlSurfaceView。 当我在旧 api 中获得必要的纵横比时,我使用 Camera.Parameters

camParams.setPreviewSize(previewW, previewH);
       if(isPictureSizeSupported(camParams, newSize)) {
           camParams.setPictureSize(newSize.getWidth(), newSize.getHeight());
       }

如果不调用,预览会被拉伸

问:如何在camera 2中得到这样的效果api?

我迁移到 SurfaceView 并在 SurfaceHolder 上使用了 setFixedSize()。 正如 Documentation 所说:

For drawing to a SurfaceView: Once the SurfaceView's Surface is created, set the size of the Surface with setFixedSize(int, int) to be one of the sizes returned by getOutputSizes(SurfaceHolder.class) and then obtain the Surface by calling getSurface()