简体   繁体   English

Camera2预览拉伸

[英]Camera2 preview stretched

On my Moto E, I want my preview to be full screen hence i have set the texture view's dimension to be full screen ie 540*960by overriding onMeasure, but using camera2 api the closest match of preview size that i am getting is 768*432 which is of the same aspect ratio. 在我的Moto E上,我希望预览为全屏显示,因此我通过覆盖onMeasure将纹理视图的尺寸设置为全屏显示,即540 * 960,但使用camera2 api,我得到的预览尺寸的最匹配值为768 * 432具有相同的长宽比。 Google sample suggests that "Initially, output stream images from the Camera2 API will be rotated to the native device orientation from the sensor's orientation, and the TextureView will default to scaling these buffers to fill it's view bounds. If the aspect ratios and relative orientations are correct, this is fine." Google示例建议:“最初,Camera2 API的输出流图像将从传感器的方向旋转到本机设备的方向,并且TextureView将默认缩放这些缓冲区以填充其视图范围。如果宽高比和相对方向为是的,这很好。” But even when in native orientation I am getting stretched previews. 但是,即使以本机方向显示,我也可以预览。 Even if I setTransform to Identity matrix, I don't know how the preview is still scaled automatically to fill the whole screen. 即使将Transform设置为Identity矩阵,我也不知道预览如何自动缩放以填满整个屏幕。

I also encountered this problem and solved it like this: 我也遇到了这个问题,并像这样解决了它:

re-set surfaceview params (width and heigth). 重新设置Surfaceview参数(宽度和高度)。

ViewTreeObserver observer = mSurfaceView.getViewTreeObserver();
observer.addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() 
{
    @Override
    public void onGlobalLayout() 
    {
        FrameLayout.LayoutParams surfaceParams = (FrameLayout.LayoutParams) mSurfaceView.getLayoutParams();
        surfaceParams.height = screenHeight;
        surfaceParams.width = screenWidth;
        mSurfaceView.setLayoutParams(surfaceParams);

        mSurfaceView.getViewTreeObserver().removeGlobalOnLayoutListener(this);
    }
});

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM