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
920 stars 208 forks source link

Pictures are not saved as shown on the preview on iOS #226

Closed migalv closed 1 year ago

migalv commented 1 year ago

Steps to Reproduce

  1. Download & install the camerawesome/example
  2. Take a picture in 16:9 or 4:3
  3. Check the output

Expected results

The output pictures should look like the image shown in the camera preview.

Actual results

The output pictures are "cut".

Here are some examples when taking pictures with different aspect ratios
16:9 4:3

About your device

Brand Model OS
Apple iPhone XR 13.5

PS

BTW let me say again that I love the package, great work! I hope all my issues are not too bothering. I'm just trying to help 😅 let me know if I can help in any other way. Once all these issues are resolved I'll surely make a YouTube video on how to make the most out of CamerAwesome 1.0.0 because I truly believe that it's the best package for native camera integration.

g-apparence commented 1 year ago

Thank you for your kind words 🙏🏻. Feedbacks are never bothering us. That's how we can improve so please do.

2math commented 1 year ago

Same on my side (iPhoneX). It crops the image a bit when capturing in portrait mode, but when is in landscape mode it saves the image in 3:4 instead of 16:9 and crops the image a lot on the sides.

I have notice that even I set the preferedOrientations to all, on the camera screen they are forced to portraitUp only. I guess this is done on the plugin level?

2math commented 1 year ago

OK, I see https://github.com/Apparence-io/CamerAwesome/issues/241 where is explained the orientation problem as expected.

I have to mention on Pixel 6 the camera works super and saves the images as per the Camera Preview.

To be honest I was using the pre 1.0.0 version and was quite satisfied with it, but was pushed by the users to upgrade it as on that version we have an issue with saved images been bigger then the preview. I hope the issue with croped images on iOS will be solved soon.

Thank you in advance and thank you for the good job!

aavinashj commented 1 year ago

this is also the case for android devices. In my Pixel 6 pro the frame shown in preview is not he same in the frame in analysis mode the image is getting cropped from the bottom

2math commented 1 year ago

Hi @g-apparence, do you know if there is any progress on that task? Thanks in advance!

Alnik9 commented 1 year ago

Fast workaround for this problem is to use other delegate method to create image. CameraPictureController.m

- (void)captureOutput:(AVCapturePhotoOutput *)output didFinishProcessingPhoto:(AVCapturePhoto *)photo error:(NSError *)error {

    selfReference = nil;
    if (error) {
        _completion(nil, [FlutterError errorWithCode:@"CAPTURE ERROR" message:error.description details:@""]);
        return;
    }

    // Add exif data
    ExifContainer *container = [[ExifContainer alloc] init];
    [container addCreationDate:[NSDate date]];

    // Save GPS location only if provided
    if (_saveGPSLocation) {
        CLLocationManager *locationManager = [CLLocationManager new];
        CLLocation *location = [locationManager location];
        [container addLocation:location];
    }

    NSData *data = photo.fileDataRepresentation;

    UIImage *capturedImage = [UIImage imageWithCGImage:[UIImage imageWithData:data].CGImage
                                                 scale:1.0
                                           orientation:[self getJpegOrientation]];

    NSData *imageWithExif = [UIImageJPEGRepresentation(capturedImage, 1.0) addExif:container];

    bool success = [imageWithExif writeToFile:_path atomically:YES];
    if (!success) {
        _completion(nil, [FlutterError errorWithCode:@"IOError" message:@"unable to write file" details:nil]);
        return;
    }
    _completionBlock();
}
migalv commented 1 year ago

Hey @Alnik9 could you create a PR with this change, please? I would love to try it out!

I'm not sure how to change this in my code

migalv commented 1 year ago

@g-apparence Hey do you have any news on this being fixed?

Let me know if I can help in any way, I would be happy to contribute if I can.

g-apparence commented 1 year ago

Sorry didn't have time to work on this. As it seems someone found the solution this could be interesting to try this with the approval of our iOS master.

@Alnik9 would you create a PR with your changes?

migalv commented 1 year ago

Hello @g-apparence, I see that you guys are actively working on CamerAwesome again.

Did you have a chance to solve this? Is there a PR in development at the moment? I think this is a pretty big problem for the iOS camera.

istornz commented 1 year ago

@migalv This problem is very difficult to fix. On Android, cameraX handle the aspect ratio crop by itself, on iOS we need to do it manually so this is not perfect...

I will add the "help wanted" label if someone can help us on this bug... I think the fix provided by @Alnik9 just remove the aspect ratio cropping ... I can disable the crop with an option.

Currently here is a list of what works (if you can confirm it could be nice @migalv ):

So only portrait 4:3 not work, is it correct?

istornz commented 1 year ago

Ok so, new update @migalv !

I tried to make the portrait 4:3 work and I think I had found a solution 👍 I will try this solution tomorrow to know if it's a fix or not 👍

migalv commented 1 year ago

Hey great news @istornz thanks a ton!

Currently here is a list of what works (if you can confirm it could be nice @migalv ):

I surely can test it. Should I test it with the latest version or a certain PR. Let me know :)

istornz commented 1 year ago

@migalv Ok so I published the fix, I tested it on iPhone 14 Pro + iPhone X + iPad Pro 2018 it seems working on both portrait & landscape orientation.

If you can test on the branch fix/ios-aspect-ratio-4_3 it will be nice!