Rotating phone quickly 180 degrees, camera preview turns upside down

前端 未结 2 1574
旧时难觅i
旧时难觅i 2020-11-27 07:43

I have a custom camera application. When I rotating the phone by 90, camera preview works fine. But when I rotate phone quickly 180 degree, camera preview turns upside down.

相关标签:
2条回答
  • 2020-11-27 07:47

    You can use OrientationEventListener to trigger recalculation of camera rotation.

    Add to your activity:

    private OrientationEventListener orientationListener = null;
    

    to onCreate():

    orientationListener = new OrientationEventListener(this) {
        public void onOrientationChanged(int orientation) {
            setCameraDisplayOrientation(CustomCameraActivity.this, cameraId, camera);
        }
    };
    

    to surfaceCreated():

    orientationListener.enable();
    

    to surfaceDestroyed():

    orientationListener.disable();
    

    Now, it almost works. To make setCameraDisplayOrientation() more robust,

    1. add check for camera != null
    2. only call camera.setDisplayOrientation(result) (or perform any heavy-lifting) if result changed since last time the function was called.
    0 讨论(0)
  • 2020-11-27 08:05

    android:configChanges="keyboardHidden|orientation|screenSize"

    Add this line in your Android Manifest file after declaring all activities in activity tags *

    like:
    
    <activity android:name="com.geeklabs.ActivityMain"
                android:configChanges="keyboardHidden|orientation|screenSize" />
    

    May be it will helps you.

    0 讨论(0)
提交回复
热议问题