我的问题很简单:
如何获得
android.hardware.Camera2
1:1比例且不像Instagram那样变形的Android ?
我使用GoogeSamples项目android-Camera2Basic进行了测试。但是,当我以1:1的比例更改预览时,图像变形。有人对此有想法吗?
谢谢@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);
}
}
}
}
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句