flutter / flutter

Flutter makes it easy and fast to build beautiful apps for mobile and beyond
https://flutter.dev
BSD 3-Clause "New" or "Revised" License
164.38k stars 27.12k forks source link

Photos are coming up rotated with the camera: ^0.2.6 package on Samsung Devices #25232

Closed ThinkDigitalSoftware closed 1 month ago

ThinkDigitalSoftware commented 5 years ago

Originally posted by @goderbauer in https://github.com/flutter/flutter/issues/10895#issuecomment-445050911

Although this is a dupe of #10895, it was requested that a new issue is opened if the issue still exists. I'm testing on a Samsung Galaxy S9+ and images are still being saved as rotated 270° even when the device is locked into the vertical orientation. This is on latest (as of now) camera: ^0.2.6. I also noticed that an Image taken with the front-facing camera is rotated 90°.

Update: This seems to be an issue only on Samsung devices. I'm not able to reproduce this on the Android Emulator (8.1.0) nor the Google Pixel. (9.0)

Steps to reproduce:

  1. Clone the flutter/ plugins repo and run the example camera app on a Samsung device.
  2. Notice that images are saved rotated. You can see this in the bottom right corner of the screenshot below.

whatsapp image 2018-12-11 at 11 42 41 am

goderbauer commented 5 years ago

/cc @mklim Who recently looked at camera orientation on Android.

zoechi commented 5 years ago

Might be a dup of #16587

mklim commented 5 years ago

@ThinkDigitalRepair thanks for the bug report! I'm still working on getting an S9 to test this with, but so far I haven't been able to reproduce this on the other Samsung devices that I've tried it on unfortunately. Have you seen this happen on other Samsung devices besides an S9?

I also have a clarifying question.

images are still being saved as rotated 270° even when the device is locked into the vertical orientation

When you say "locked" here do you mean when the UI is locked to portrait mode, or when the device is physically being held vertically? I'm asking because previously photo orientation was set to match the UI on Android, so photos taken while the device was locked to portrait mode would always be vertical. But flutter/plugins#942 deliberately changed this behavior so that all photos match how the device is physically orientated instead, ignoring the UI rotation.

ThinkDigitalSoftware commented 5 years ago

Have you seen this happen on other Samsung devices besides an S9? Yes, with an S7 edge

When you say "locked" here do you mean when the UI is locked to portrait mode, or when the device is physically being held vertically?

The device rotation mode would be set to portrait and the ui as well.

You can tell by looking at the screenshot above that the device is in portrait mode and is actually oriented vertically, since it's pointed at the laptop, which is sitting flat

matte5031 commented 5 years ago

Same issue here, any updates?

BoHellgren commented 5 years ago

I made a minimal camera app to illustrate the problem. Using camera 0.2.9+1.

image

On my Samsung Galaxy, this works as expected when the mobile is in a vertical (portrait) position, but not when horizontal (landscape).

This bug stops me from using Flutter for my app. Can we hope for a solution anytime soon?

BoHellgren commented 5 years ago

(The built-in camera app does not behave like this. Then a person standing up remains vertical no matter how I turn the phone. But with the app listed above, something happens when I turn the phone past 45 degrees.)

BoHellgren commented 5 years ago

The camera plugin uses the android.hardware.camera2 API. In CameraPlugin.java, a search for orientation gets 31 hits. I suspect that the problem is related to how orientation changes are handled.

I can bypass this bug by wrapping the CameraPreview widget with a RotatedBox widget: RotatedBox(quarterTurns: 3, child: CameraPreview(controller))

But I would much prefer to have this bug fixed. Is anyone listening?

AlexVegner commented 5 years ago

We have same issues with device: Samsung Note 8, Android 9

gianlucainnocente commented 4 years ago

Same problem with Galaxy S6/7

TahaTesser commented 4 years ago

Hi @ThinkDigitalSoftware @gianlucainnocente Are you still experiencing with latest stable?

I wasn't able to reproduce this issue on Galaxy M30 Thank you

ThinkDigitalSoftware commented 4 years ago

Hi, I'm not on a project that uses it currently

On Mar 17, 2020 2:40 AM, Taha Tesser notifications@github.com wrote:

Hi @ThinkDigitalSoftwarehttps://github.com/ThinkDigitalSoftware @gianlucainnocentehttps://github.com/gianlucainnocente Are you still experiencing with latest stable? Thank you

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHubhttps://github.com/flutter/flutter/issues/25232#issuecomment-599973315, or unsubscribehttps://github.com/notifications/unsubscribe-auth/AFPYO7MQQS45IXCWVAKHYM3RH5AQHANCNFSM4GJYOASA.

BoHellgren commented 4 years ago

I tried again with camera: 0.5.7+4 and Flutter 1.12.13+hotfix.8 • channel stable •.

Test program below.

With a Samsung Galaxy S10e the problem is the same. Portrait mode is OK, in Landscape mode the image is rotated 90 degrees clockwise. Changing ResolutionPreset makes no difference. Front facing camera makes no difference.

With a Samsung Galaxy S4 I now get this error message:

E/CameraDevice-0-LE(19471): Surface with size (w=720, h=480) and format 0x21 is not valid, size not in valid set: [4128x3096, 4128x2322, 3264x2448, 3264x1836, 2560x1920, 2048x1536, 2048x1152, 1920x1080, 1280x960, 1280x720, 640x480]


import 'package:flutter/material.dart';
import 'package:camera/camera.dart';

void main() => runApp(MyApp());

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Flutter Demo',
      theme: ThemeData(
        primarySwatch: Colors.blue,
      ),
      home: MyHomePage(title: 'Minimal Camera App'),
    );
  }
}

class MyHomePage extends StatefulWidget {
  MyHomePage({Key key, this.title}) : super(key: key);
  final String title;

  @override
  _MyHomePageState createState() => _MyHomePageState();
}

class _MyHomePageState extends State<MyHomePage> {
  CameraController controller;

  @override
  void initState() {
    super.initState();
    initCamera();
  }

  void initCamera() async {
    List<CameraDescription> cameras = await availableCameras();
    controller = CameraController(cameras[0], ResolutionPreset.medium);
    await controller.initialize();
    setState(() {});
  }

  @override
  Widget build(BuildContext context) {
    return
      controller == null
      ? Text('Wait)')
      : CameraPreview(controller);
  }
}
VadymPinchuk commented 4 years ago

Same now with:

mikeb1986 commented 2 years ago

Hi, I was directed to this issue via https://github.com/flutter/flutter/issues/104134

I have same issue as noted above https://github.com/flutter/flutter/issues/25232#issuecomment-600208893

Essentially, taking a picture when the phone is in landscape mode saves the image sidweways.

I noticed actually this issue started with the camera plugin version 0.9.0 and onwards. Previously we used 0.8.1+3 which was working fine.

What I noticed now is if the app is fixed in portrait mode via setPreferredOrientations(...) then rotating the phone 90 degrees to take a picture will just save it sideways as portrait.

Is there a way to not have a fixed orientation on the camera even though the app itself is always portrait mode?

I was able to reproduce the issue using the camera example from the official flutter plugin page - though I had to add logic to call setPreferredOrientations(...) to keep the app in portraitUp mode.

https://github.com/flutter/plugins/blob/main/packages/camera/camera/example/lib/main.dart

grvsaxena419 commented 1 year ago

I'm facing this as well, just wondering if this has been fixed or if there are any mitigations to store the image in the correct orientation.

juanfactor88 commented 1 year ago

Im facing the same issue, any updates on this?

russell-g5628 commented 10 months ago

Galaxy A Services Always~

TecHaxter commented 7 months ago

image

Check the height and width values, its giving a landscape right image Although the controller is initialized with locked device orientation to portrait up await _controller!.initialize(); await _controller!.lockCaptureOrientation(DeviceOrientation.portraitUp);

ChurikiTenna commented 5 months ago

I am experiencing this on Galaxy too. lockCaptureOrientation does not work.

Is anyone working on this or is there any workarounds?

quoc-huynh-cosee commented 2 months ago

I'm also experiencing it on a Xiaomi 12 Lite. Any updates on this?

darshankawar commented 2 months ago

Revisiting the issue, I used the latest camera plugin example, ran on S10 using latest stable version in which I observed that the photo taken and shown in the preview is in correct order, as below:

Screenshot 2024-07-02 at 4 54 46 PM

@ThinkDigitalSoftware can you try the same again at your end and confirm ?

github-actions[bot] commented 1 month ago

Without additional information, we are unfortunately not sure how to resolve this issue. We are therefore reluctantly going to close this bug for now. If you find this problem please file a new issue with the same description, what happens, logs and the output of 'flutter doctor -v'. All system setups can be slightly different so it's always better to open new issues and reference the related ones. Thanks for your contribution.

ThinkDigitalSoftware commented 1 month ago

I cannot confirm anymore. I am no longer developing. Thank you for the work though!

github-actions[bot] commented 4 weeks ago

This thread has been automatically locked since there has not been any recent activity after it was closed. If you are still experiencing a similar issue, please open a new bug, including the output of flutter doctor -v and a minimal reproduction of the issue.