我的问题很简单:
如何获得安卓系统android.hardware.Camera2
像 Instagram 一样 1:1 比例且不变形?
我用 GoogeSamples 项目进行了测试android-Camera2Basic https://github.com/googlesamples/android-Camera2Basic。但是当我以 1:1 的比例更改预览时,图像会变形。有人对此有什么想法吗?
谢谢@CommonsWare。
我按照你的建议使用负边距(顶部和底部)并且它有效。
为此,我只需更新自动调整纹理视图 https://github.com/googlesamples/android-Camera2BasicGoogeSamples 项目android-Camera2Basic https://github.com/googlesamples/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);
}
}
}
}
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)