Apparence-io / CamerAwesome

📸 Embedding a camera experience within your own app shouldn't be that hard. A flutter plugin to integrate awesome Android / iOS camera experience.
https://ApparenceKit.dev
MIT License
976 stars 256 forks source link

How to make the camera square? #64

Closed naamapps closed 3 years ago

naamapps commented 3 years ago

Awesome package!

However I have an issue with making the camera preview window square. I followed the example and actually copied the function buildSizedScreenCamera to build the sized camera.

If I put the height and the width as the width of the screen (to create a square), the camera preview will not be square and the camera feed will become distorted.

This is the code:

Container(
    height: MediaQuery.of(context).size.width,
    width: MediaQuery.of(context).size.width,
    child: CameraAwesome(
        fitted: true,
        ...
    ),
);

And for some reason, setting the height of the container to 300 (like in the example), the camera is not distorted. But again, not square.

I think it's because in _CameraPreviewWidget when fitted is true, the FittedBox fit is set to fit: BoxFit.fitWidth, But I'm not really sure this is the cause of the problem.

Hope to get a solution, Thank you!

naamapps commented 3 years ago

Okay, so I found out that setting the height to MediaQuery.of(context).size.width.roundToDouble(), fixes the issue. Although it is not perfect either. The camera outputs a zoomed in image (not the whole width and height of the cropped camera feed). So when pressing the shoot button, the actual image taken is like a zoomed out version of the square preview (even after cropping it to a square image).

g-apparence commented 3 years ago

You should use the same technic as the inner code to crop the content into a square. Our plugin rely on the device preview size for ratio so you have to crop it. let me know if you need help.

sjayadeep commented 3 years ago

I'm using the following code to create the camera. But like he mentioned the preview is a bit zoomed. If I use fitted true the image looks stretched.

CameraAwesome(
                    // onPermissionsResult: _onPermissionsResult,
                    selectDefaultSize: (availableSizes) {
                      _photoSize = ValueNotifier(availableSizes[0]);
                      return availableSizes[0];
                    },
                    captureMode: _captureMode,
                    photoSize: _photoSize,
                    sensor: _sensor,
                    fitted: false,
                    switchFlashMode: _switchFlash,
                    zoom: _zoomNotifier,
),
sjayadeep commented 3 years ago

The issue is I think, the Camera preview is always in 9:16 ratio, and takes the photo in the ratio we specify. Whatever the resolution we give the preview is always in 9:16.

Just try wrapping the CameraAwesome widget inside a Transform.scale with scale: 0.4

devibrahimkarahan commented 3 years ago

But if we want to record square ? How can we achieve that without ffmpeg ?