现象
使用TextureView预览发现相机拉伸了;
原因
camera尺寸与TextureView尺寸不匹配,像素点矩阵偏移;
解决方案
获取camera参数 设置到TextureView;
代码
public void onSurfaceTextureAvailable(SurfaceTexture surface, int width, int height) {
mCamera = Camera.open(Camera.CameraInfo.CAMERA_FACING_BACK);
try {
mCamera.setPreviewTexture(surface);
mCamera.startPreview();
Camera.Size size = mCamera.getParameters().getPreviewSize();
ViewGroup.LayoutParams layoutParams = mTextureView.getLayoutParams();
layoutParams.width = size.width;
layoutParams.height = size.height;
mTextureView.setLayoutParams(layoutParams);
} catch (IOException ioe) {
Log.d(TAG, ioe.toString());
}
}