Crop camera preview for TextureView

后端 未结 6 458
借酒劲吻你
借酒劲吻你 2020-12-05 00:32

I have a TextureView with a fixed width and height and I want to show a camera preview inside of it. I need to crop the camera preview so that it doesn\'t look stretched ins

6条回答
  •  无人及你
    2020-12-05 01:17

    I have just made a working app where I needed to show a preview with x2 of the actual input without getting a pixelated look. Ie. I needed to show the center part of a 1280x720 live preview in a 640x360 TextureView.

    Here is what I did.

    Set the camera preview to x2 resolution of what I needed:

    params.setPreviewSize(1280, 720);
    

    And then scale the texture view accordingly:

    this.captureView.setScaleX(2f);
    this.captureView.setScaleY(2f);
    

    This runs without any hiccups on small devices.

提交回复
热议问题