RedApparat / Fotoapparat

Making Camera for Android more friendly. 📸
Apache License 2.0
3.82k stars 407 forks source link

Incorrect camera view orientation when device turned upside down #262

Closed dlevache-pro closed 5 years ago

dlevache-pro commented 6 years ago

When the screen orientation is not locked, the system does not create a new activity when the device is turned upside down (from portrait to reverse portrait or from landscape to reverse landscape, with no intermediate orientation). In both these cases, the camera view displays images in the wrong orientation.

With an intermediate orientation (portrait during the landscape to reverse landscape switch), there is no problem.

What are you trying to achieve or the steps to reproduce?

Using the code from the sample:

What was the result you received?

The camera view is rendered upside down. screenshot_20180606-114916

What did you expect?

Video preview is rendered in the correct orientation

Context:

dmitry-zaitsev commented 6 years ago

Thanks for reporting that. I will take a look at it.

marekfoltyn commented 6 years ago

The same bug appears in Samsung Galaxy S5. The last thing required to fix in order to have perfect camera view 📸 :)

marekfoltyn commented 6 years ago

Update: Since the android does not recreating Activity when switching landscape modes, it has to be done manually. I fixed this issue by manual detecting Display orientation. When landscape <-> reversed_landscape change is detected the following code is called:

runOnUiThread {
    fotoapparat.stop()
    fotoapparat.start()
}
ijwhelan commented 5 years ago

Hey @marekfoltyn, I'm running into this same issue when going from landscape -> reverse landscape. How are you going about manually detecting display orientation?

rdsarna commented 5 years ago

Hi @ijwhelan, if you're targeting API 17+ then the following fix should work - Include this file in your project - ReverseOrientationObserver.kt

Then, in your onCreate() add the following code -

if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) {
    reverseOrientationObserver = ReverseOrientationObserver(this) {
        fotoapparat.stop()
        fotoapparat.start()
    }
}

And in onDestroy() add -

reverseOrientationObserver?.quit()
reverseOrientationObserver = null

@dmitry-zaitsev Could this be added to the sample app in this repo if I raise a PR?

balazsbanto commented 5 years ago

Hi @rdsarna Your link does not work. Could you fix it please? I also encountered this problem. Thanks in advance!

rdsarna commented 5 years ago

@balazsbanto Sorry about that, fixed now.