gpt4 book ai didi

android - 如何使用 1 :1 ratio like Instagram? 获取 Android Camera2

转载 作者:塔克拉玛干 更新时间:2023-11-01 22:09:02 25 4
gpt4 key购买 nike

我的问题很简单:

How to get an Android android.hardware.Camera2 with 1:1 ratio and without deformation like Instagram?

我使用 GoogeSamples 项目进行了测试 android-Camera2Basic .但是当我以 1:1 的比例更改预览时,图像变形了。有人对此有想法吗?

enter image description here

最佳答案

感谢@CommonsWare。

我按照您的建议使用负边距(顶部和底部)并且有效。

为此,我只需更新 AutoFitTextureView GoogeSamples 项目 android-Camera2Basic这样:

public class AutoFitTextureView extends TextureView {

//...
private boolean mWithMargin = false;

//...

@Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
super.onMeasure(widthMeasureSpec, widthMeasureSpec);
int width = MeasureSpec.getSize(widthMeasureSpec);
int height = MeasureSpec.getSize(heightMeasureSpec);
int margin = (height - width) / 2;

if(!mWithMargin) {
mWithMargin = true;
ViewGroup.MarginLayoutParams margins = ViewGroup.MarginLayoutParams.class.cast(getLayoutParams());
margins.topMargin = -margin;
margins.bottomMargin = -margin;
margins.leftMargin = 0;
margins.rightMargin = 0;
setLayoutParams(margins);
}

if (0 == mRatioWidth || 0 == mRatioHeight) {
setMeasuredDimension(width, height);
} else {
if (width < height) {
setMeasuredDimension(width, width * mRatioHeight / mRatioWidth);
} else {
setMeasuredDimension(height * mRatioWidth / mRatioHeight, height);
}
}
}
}

enter image description here

关于android - 如何使用 1 :1 ratio like Instagram? 获取 Android Camera2,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34638651/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com