Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it possible to crop camera preview?

I have not found any way to crop camera ppreview and then display it on the SurfaceView.

Android - Is it possible to crop camera preview?

like image 560
Anderson Avatar asked Dec 22 '11 09:12

Anderson


People also ask

Can you crop Webcam?

Using OBS to crop webcam allows you to cut out irrelevant parts of the webcam video. To get a perfect cut, you have to crop from the side of the webcam screen. This is the easiest way to remove irrelevant background from the picture, and there is no better and convenient way to do this than the OBS tool.

Can I crop my zoom camera?

To control the camera in your Zoom Room: Start or join a meeting. Tap the Camera Control icon. Use the icons on the Camera Control popup to zoom and pan until the camera is in the position you need.


1 Answers

You can do this without overlay views (which won't work in all situations).

Subclass ViewGroup, add the SurfaceView as the only child, then:

  1. in onMeasure supply the cropped dimensions you want.
  2. in onLayout, layout the SurfaceView with the un-cropped dimensions.

basically,

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 );
    }
  }
}
like image 190
momo Avatar answered Oct 04 '22 10:10

momo