Reputation: 611
When I set my SurfaceView as target surface for my camera preview(as in and-dev tutorial for camera API 1) it will stretching picture from camera as far as needed for filling whole surface with that picture. How I can disable that? I want to have 2 black strips for areas with no appropriate image data from camera rather then scaled image over all surface.
Upvotes: 0
Views: 313
Reputation: 5950
Create a custom view with an inner SurfaceView
as @momo reports in his solution (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 );
}
}
}
Upvotes: 1