Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

解决相机拉伸变形问题 #270

Open
zhangwanggit opened this issue Dec 29, 2021 · 0 comments
Open

解决相机拉伸变形问题 #270

zhangwanggit opened this issue Dec 29, 2021 · 0 comments

Comments

@zhangwanggit
Copy link

使用中发现扫描的二维码被拉伸了,本来是正方形的,拉伸成长方形的,虽然不影响使用,但是显示效果不好,排查代码,发现是CameraConfigurationManager下findBestPreviewSizeValue方法出现问题,该方法目的是找到最合适的预览尺寸,修改后的代码如下

private static Point findBestPreviewSizeValue(CharSequence previewSizeValueString, Point screenResolution) {
int bestX = 0;
int bestY = 0;
float diff = Integer.MAX_VALUE;
for (String previewSize : COMMA_PATTERN.split(previewSizeValueString)) {

        previewSize = previewSize.trim();
        int dimPosition = previewSize.indexOf('x');
        if (dimPosition < 0) {
            Log.w(TAG, "Bad preview-size: " + previewSize);
            continue;
        }

        int newX;
        int newY;
        try {
            newX = Integer.parseInt(previewSize.substring(0, dimPosition));
            newY = Integer.parseInt(previewSize.substring(dimPosition + 1));
        } catch (NumberFormatException nfe) {
            Log.w(TAG, "Bad preview-size: " + previewSize);
            continue;
        }

        //int newDiff = Math.abs(newX - screenResolution.x) + Math.abs(newY - screenResolution.y);
        float newDiff = Math.abs((float) newX/newY-(float)screenResolution.x/screenResolution.y);
        if (newDiff == 0) {
            bestX = newX;
            bestY = newY;
            break;
        } else if (newDiff < diff) {
            bestX = newX;
            bestY = newY;
            diff = newDiff;
        }

    }

    if (bestX > 0 && bestY > 0) {
        return new Point(bestX, bestY);
    }
    return null;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant