xamarin / XamarinCommunityToolkit

The Xamarin Community Toolkit is a collection of Animations, Behaviors, Converters, and Effects for mobile development with Xamarin.Forms. It simplifies and demonstrates common developer tasks building iOS, Android, and UWP apps with Xamarin.Forms.
MIT License
1.59k stars 471 forks source link

[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 2 years ago

brettnguyen commented 2 years ago

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

Workaround

Bitmap so can be used to correct the images not videos

Reproduction imagery

Juanoxt890 commented 2 years ago

Same here!

Juanoxt890 commented 2 years ago

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

gurvinderbini commented 2 years ago

any update on this issue?

jfversluis commented 2 years ago

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

brettnguyen commented 2 years ago

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

frarcedev commented 2 years ago

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 commented 2 years ago

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 commented 1 year ago

@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 commented 1 year ago

I have this issue when recording video

cuethenoise commented 1 year ago

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 commented 1 year ago

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 commented 1 year ago

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 commented 1 year ago

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 commented 1 year ago

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 commented 1 year ago

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 commented 1 year ago

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?