当我将SurfaceView设置为我的相机预览的目标表面时(如相机API 1的and-dev tutorial),它将从相机拉伸图片,直到用该图片填充整个表面。我怎么能禁用它?我希望有2个黑色条带用于没有来自相机的适当图像数据的区域,而不是所有表面上的缩放图像。
答案 0 :(得分:1)
使用内部SurfaceView
创建自定义视图@momo在他的解决方案(https://stackoverflow.com/a/21653728/2124387)中报告:
public class CroppedCameraPreview extends ViewGroup {
private SurfaceView cameraPreview;
public CroppedCameraPreview( Context context ) {
super( context );
// i'd probably create and add the SurfaceView here, but it doesn't matter
}
@Override
protected void onMeasure( int widthMeasureSpec, int heightMeasureSpec ) {
setMeasuredDimension( croppedWidth, croppedHeight );
}
@Override
protected void onLayout( boolean changed, int l, int t, int r, int b ) {
if ( cameraPreview != null ) {
cameraPreview.layout( 0, 0, actualPreviewWidth, actualPreviewHeight );
}
}
}