Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Camera Stretching in flutter #34498

Closed
Loopex2019 opened this issue Jun 14, 2019 · 12 comments
Closed

Camera Stretching in flutter #34498

Loopex2019 opened this issue Jun 14, 2019 · 12 comments

Comments

@Loopex2019
Copy link

I used the Camera Package and the CameraPreview() worked fine for me . But the Problem that it is always stretching on the Android Emulator . So i used a real Android Device and it is always stretching too . Does anybody have an Idea of why is that happening and how to solve it ?

@khflab
Copy link

khflab commented Jun 16, 2019

You must provide more information like:

  • Could you provide a print screen?
  • Can you replicate it on another Android Device?
  • What Flutter version/channel you are using
  • What image you are running on Android Emulator
  • What Android Device/OS you are using

Only with this we can help.

@Loopex2019
Copy link
Author

Loopex2019 commented Jun 17, 2019

Great i am using Android Oreo . And i was using Samsung Galaxy J7 Core. And i tried it on another Android Devices and both of them had the same Issues. These Devices were Samsung Galaxy J5 and
Samsung Galaxy A50. And here is a Footage of the Stretching in Samsung Galaxy J7 Core :
Screenshot_20190617-172516
In Flutter i am using the latest Version 1.5 and i am on the stable channel. And i am not using Android Emulators , i am using real Android Devices.

@KonstantinKai
Copy link

KonstantinKai commented Jun 21, 2019

Hi, I have the same issue.
My device:

OnePlus 6, Android 9
[✓] Flutter (Channel master, v1.7.4-pre.71, on Mac OS X 10.14.5 18F203, locale en-UA)

[✓] Android toolchain - develop for Android devices (Android SDK version 28.0.3)
[✓] Xcode - develop for iOS and macOS (Xcode 10.2.1)
[!] iOS tools - develop for iOS devices
    ✗ libimobiledevice and ideviceinstaller are not installed. To install with Brew, run:
        brew update
        brew install --HEAD usbmuxd
        brew link usbmuxd
        brew install --HEAD libimobiledevice
        brew install ideviceinstaller
[✓] Android Studio (version 3.4)
[✓] IntelliJ IDEA Community Edition (version 2019.1.1)
[✓] VS Code (version 1.35.1)
[✓] Connected device (2 available)

@KonstantinKai
Copy link

KonstantinKai commented Jun 22, 2019

@Loopex2019 I found a workaround that fixes this issue on stackoverflow

@Loopex2019
Copy link
Author

Great I will try . If it succeed , I will tell

@Loopex2019
Copy link
Author

Well no it still the same Issue . I don't really know what to do ?

@KonstantinKai
Copy link

@Loopex2019, hmm... Look at my code. It works for me.

[✓] Flutter (Channel master, v1.7.9-pre.2, on Mac OS X 10.14.4 18E227, locale en-UA)

[✓] Android toolchain - develop for Android devices (Android SDK version 28.0.3)
[✓] Xcode - develop for iOS and macOS (Xcode 10.2.1)
[✓] iOS tools - develop for iOS devices
[✓] Chrome - develop for the web
[✓] Android Studio (version 3.4)
[✓] VS Code (version 1.35.1)
[✓] Connected device (5 available)
@override
  Widget build(BuildContext context) {
    Widget child = Container();

    if (_inited) {
      final size = MediaQuery.of(context).size;
      final deviceRatio = size.width / size.height;
      child = Transform.scale(
        scale: _controller.value.aspectRatio / deviceRatio,
        child: Center(
          child: AspectRatio(
            aspectRatio: _controller.value.aspectRatio,
            child: CameraPreview(_controller),
          ),
        ),
      );
    }

    return WithStatusBarStyle(
      child: Scaffold(
        backgroundColor: Colors.black,
        body: Stack(
          fit: StackFit.expand,
          children: <Widget>[
            child,
            // ...
            // another UI
            // ...
          ],
        ),
      ),
    );
  }

@Loopex2019
Copy link
Author

I did the same as you : and here is the result
20190629_145846

@Loopex2019
Copy link
Author

And here is my Code :
Widget _cameraPreview(double deviceWidth) {
final size = MediaQuery.of(context).size;
final deviceRatio = size.width / size.height;
if (_controller?.value?.isInitialized == null) {
return Center(child: CircularProgressIndicator());
} else {
return OrientationBuilder(
builder: (context, orientation) {
if (orientation == Orientation.landscape) {
return Transform.scale(
scale: _controller.value.aspectRatio / deviceRatio,
child: Center(
child: AspectRatio(
aspectRatio: _controller.value.aspectRatio,
child: CameraPreview(_controller),
),
),
);
} else {
return Transform.scale(
scale: _controller.value.aspectRatio / deviceRatio,
child: Center(
child: AspectRatio(
aspectRatio: _controller.value.aspectRatio,
child: CameraPreview(_controller),
),
),
);
}
},
);
}
}

@Loopex2019
Copy link
Author

Hi there i realized that the StackOverflow Solution only works for The Back Camera not the front one. So it is only solved on the back Camera , the front still the same .

@Loopex2019
Copy link
Author

Thanks for the Support it worked for me fine

@github-actions
Copy link

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.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Aug 29, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants