关于拉伸问题,要使预览不变形,需要使用Matrix:
首先把视频区移动到View区,使两者中心点重合。
matrix.preTranslate((textureViewWidth - viewWidth) / 2, (textureViewHeight - viewHeight) / 2);
其次,因为默认视频是fitXY的形式显示的,所以首先要缩放还原回来。
matrix.preScale(viewWidth/ textureViewWidth, viewHeight/ textureViewHeight);
最后等比例放大或缩小,直到视频区的一边和View一边相等,不相等则留白。
int rotation =getWindowManager().getDefaultDisplay().getRotation();
Matrix matrix= newMatrix();
RectF viewRect= new RectF(0, 0, viewWidth, viewHeight);
RectF bufferRect= new RectF(0, 0, mPreviewSize.getHeight(), mPreviewSize.getWidth());float centerX =viewRect.centerX();float centerY =viewRect.centerY();if (Surface.ROTATION_90 == rotation || Surface.ROTATION_270 ==rotation) {
bufferRect.offset(centerX- bufferRect.centerX(), centerY -bufferRect.centerY());
matrix