简体   繁体   中英

Android custom portrait camera and images orientation

I am writing a custom portrait camera and I am having some issues with images orientation. In details, I need always the camera to be in portrait orientation and it happens using the manifest configuration:

android:screenOrientation="portrait"

and I set in application:

customCamera.setDisplayOrientation(90);

which works, because when I rotate the device (90,180,270 degrees) I can see (from camera preview) the right image.

I don't care when the device orientation is locked (disabled), but when it's enabled, it seems that I don't get any orientation change. I always get 0 degrees using the code:

getWindowManager().getDefaultDisplay().getRotation();

Technically, I need to write to the taken picture (using exif data) 0,1,3,6 or 8 value. So, the steps are: 1) set the right orientation on custom portrait camera - DONE! 2) Preview the right picture - DONE! 3) If the device orientation in enabled, get the current rotation (0.90,180,270 degrees) 4) Write the taken picture with the right orientation exif tag.

I am using Samsung Galaxy I for the development.

The question is: How can i get the device orientation when the application shows always a custom portrait camera, which should never be rotated, but the device orientation is enabled?

Thank you, Nikolaos

You can use OrientationEventListener

OrientationEventListener mOrientationListener = new OrientationEventListener(
            this, SensorManager.SENSOR_DELAY_NORMAL) {

        @Override
        public void onOrientationChanged(int orientation) {
        }

    };

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM