小编Gra*_*sie的帖子

Camera2的SurfaceTexture预览在某些设备上延伸

我正在开发一个camera2应用程序.在Nexus 5和Nexus 4上一切正常,但在LG G2预览视频是拉伸的(仅适用于后置摄像头,前置摄像头一切都很好).我正在设置SurfaceTexture:

@Override
    protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
        super.onMeasure(widthMeasureSpec, heightMeasureSpec);
        int width = MeasureSpec.getSize(widthMeasureSpec);
        int height = MeasureSpec.getSize(heightMeasureSpec);
        float ratioSurface = width > height ? (float) width / height : (float) height / width;
        float ratioPreview = (float) mRatioWidth / mRatioHeight;
        int scaledHeight = height;
        int scaledWidth = width;
        if (ratioPreview > ratioSurface) {
            scaledHeight = (int) (((float) mRatioWidth / mRatioHeight) * width);
        } else if (ratioPreview < ratioSurface) {
            scaledWidth = (int) (height / ((float) …
Run Code Online (Sandbox Code Playgroud)

android android-layout android-camera

5
推荐指数
0
解决办法
1930
查看次数

标签 统计

android ×1

android-camera ×1

android-layout ×1