我的问题很简单:
如何以
android.hardware.Camera2
1:1的比例获得Android 而不像Instagram那样变形?
我测试了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); } } } }