Skip to content
This repository has been archived by the owner on May 1, 2024. It is now read-only.

[Bug] pictures and videos taken by cameraview on android appear rotated at 90 degrees. Only images can be fixed with bitmap not videos. #1803

Open
brettnguyen opened this issue Jan 31, 2022 · 16 comments
Labels
a/CameraView 📸 bug Something isn't working. Breaky break.

Comments

@brettnguyen
Copy link

brettnguyen commented Jan 31, 2022

Description

Images and videos appear sideways when taken on android. Rotation for where the image or video preview display on the xaml or .cs don’t correct the output nor does putting rotation in the captured media.

Stack Trace

Link to Reproduction Sample

Steps to Reproduce

  1. Download Xamarin community toolkit nuget to project
  2. Input cameraview into xaml and xaml.cs then take picture or video on android emulator or device
  3. Than view preview for either video or picture display

Expected Behavior

Not rotated

Actual Behavior

Rotated 90 degrees or sideways

Basic Information

  • Version with issue:
  • Last known good version:
  • IDE:
  • Platform Target Frameworks:
    • iOS:
    • Android:
    • UWP:
  • Android Support Library Version:
  • Nuget Packages:
  • Affected Devices:

Workaround

Bitmap so can be used to correct the images not videos

Reproduction imagery

@brettnguyen brettnguyen added the bug Something isn't working. Breaky break. label Jan 31, 2022
@Juanoxt890
Copy link

Same here!

@Juanoxt890
Copy link

@jfversluis @sthewissen @jsuarezruiz
Any update planned to fix this bug in android?
It's a stopper to create powerful components

@gurvinderbini
Copy link

any update on this issue?

@jfversluis
Copy link
Member

For the image I think I made a fix, check out #1695

@brettnguyen
Copy link
Author

@Juanoxt890 @pictos is there a fix for this issue? Will @jfversluis fix also work for previewed videos too? Can I get any answer?

@frarcedev
Copy link

frarcedev commented Sep 11, 2022

In my case I got a personal solution for this issue in the CameraFragment.android.cs in Views/CameraView/Android.
The method GetCaptureOrientation set a frontOffset when you are using a front camera to record videos, but in my opinion usually the front camera is in the top center of the device dont need apply 90 degree.
image

I changed 90 degree to 0 when it's using a front camera. That worked for me.
image

@BrendanHadley
Copy link

BrendanHadley commented Sep 14, 2022

Any update on when this will get fixed? still have the issue where it saves wrong even though the preview of the image looks fine. The top image is the cameraview preview and the bottom one is loaded in after the image gets saved.
testing
It really just does not make sense to me, must just be a sensor issue that permeates androids or something. @jfversluis

@bijington
Copy link
Contributor

@BrendanHadley I believe @jfversluis has a potential fix added at #1871 but was hoping for someone to verify it solves the issue. Are you able to assist him?

@Hackmodford
Copy link

I have this issue when recording video

@cuethenoise
Copy link

I am seeing the same thing. This is the only bug holding up my app I’m working on. I am willing to test any fixes I’d anybody needs help. Thanks!

@cuethenoise
Copy link

cuethenoise commented May 23, 2023

I think I have an actual fix for this. What is the process of committing it?

I changed the function GetCaptureOrientation in the Android Views.CameraFragment to and it works :)
image

@bijington
Copy link
Contributor

bijington commented May 23, 2023

I think I have an actual fix for this. What is the process of comitting it?

Have you checked out the PR at #1871? It contains fixes for rotation issues with photos. I believe @jfversluis was hoping to gain confidence from people testing it in their apps to know that it solves their issues

@cuethenoise
Copy link

I think I have an actual fix for this. What is the process of comitting it?

Have you checked out the PR at #1871? It contains fixes for rotation issues with photos. I believe @jfversluis was hoping to gain confidence from people testing it in their apps to know that it solves their issues

Looking at his change it appears as if he just fixed the photos and it appears to be just rotating the captured image after the fact. The better approach would be to set the correct orientation when saving the image. That is what I am doing. My fix only works with video files though at the moment.

@bijington
Copy link
Contributor

I think I have an actual fix for this. What is the process of comitting it?

Have you checked out the PR at #1871? It contains fixes for rotation issues with photos. I believe @jfversluis was hoping to gain confidence from people testing it in their apps to know that it solves their issues

Looking at his change it appears as if he just fixed the photos and it appears to be just rotating the captured image after the fact. The better approach would be to set the correct orientation when saving the image. That is what I am doing. My fix only works with video files though at the moment.

If there is a better to do it then I'm keen to see it :).

As for your solution/issue, have you tested on a Samsung device as well as another Android device? I have experienced that Samsung devices don't typically respond to the same fix as other android devices.

@cuethenoise
Copy link

I think I have an actual fix for this. What is the process of comitting it?

Have you checked out the PR at #1871? It contains fixes for rotation issues with photos. I believe @jfversluis was hoping to gain confidence from people testing it in their apps to know that it solves their issues

Looking at his change it appears as if he just fixed the photos and it appears to be just rotating the captured image after the fact. The better approach would be to set the correct orientation when saving the image. That is what I am doing. My fix only works with video files though at the moment.

If there is a better to do it then I'm keen to see it :).

As for your solution/issue, have you tested on a Samsung device as well as another Android device? I have experienced that Samsung devices don't typically respond to the same fix as other android devices.

Would the Nexus 10 emulator be good enough to test on? I didn't mean any offense. I was just thinking that surely Android has a way to correct the rotation on photos similar to how you can with video so you didn't have to essentially write the image twice?

@cuethenoise
Copy link

cuethenoise commented May 24, 2023

So the front calc was off actually. Here is the correct one:

int GetCaptureOrientation() { var screenRotation = GetDisplayRotationDegrees(); var sign = cameraType == LensFacing.Front ? 1 : -1; var result = (sensorOrientation - screenRotation * sign + 360) % 360; return result; }

The calculation is specified here:

https://developer.android.com/training/camera2/camera-preview

looks like the other issue is due to GetDisplayRotationDegrees always returning 0. I think it has something to do with the sample app being set to always display in portrait mode?

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
a/CameraView 📸 bug Something isn't working. Breaky break.
Projects
None yet
Development

No branches or pull requests

9 participants