protected void reopenCameraAtResolution ( int cameraWidth , int cameraHeight ) { if ( Looper . getMainLooper ( ) . getThread ( ) != Thread . currentThread ( ) ) { throw new RuntimeException ( "Attempted to reopenCameraAtResolution main looper thread!" ) ; } boolean releaseLock = true ; open . mLock . lock ( ) ; try { if ( verbose ) Log . i ( TAG , "Reopening camera is null == " + ( open . mCameraDevice == null ) + " state=" + open . state + " activity=" + getClass ( ) . getSimpleName ( ) ) ; if ( open . state != CameraState . OPEN ) throw new RuntimeException ( "BUG! Attempted to re-open camera when not open" ) ; if ( null == open . mCameraDevice ) { throw new RuntimeException ( "Can't re-open a closed camera" ) ; } closePreviewSession ( ) ; open . mCameraSize = null ; firstFrame = true ; CameraManager manager = ( CameraManager ) getSystemService ( Context . CAMERA_SERVICE ) ; if ( manager == null ) throw new RuntimeException ( "Null camera manager" ) ; try { open . mPreviewReader = ImageReader . newInstance ( cameraWidth , cameraHeight , ImageFormat . YUV_420_888 , 2 ) ; // Do the processing inside the the handler thread instead of the looper thread to avoid // grinding the UI to a halt open . mPreviewReader . setOnImageAvailableListener ( onAvailableListener , mBackgroundHandler ) ; configureTransform ( viewWidth , viewHeight ) ; manager . openCamera ( open . cameraId , mStateCallback , null ) ; releaseLock = false ; } catch ( IllegalArgumentException e ) { Toast . makeText ( this , e . getMessage ( ) , Toast . LENGTH_LONG ) . show ( ) ; finish ( ) ; } catch ( CameraAccessException e ) { e . printStackTrace ( ) ; } } finally { if ( releaseLock ) open . mLock . unlock ( ) ; } }
Re - opens the camera with the same settings at the specified resolution . It is assumed that you know what you re doing and that this is a valid resolution .