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

photo and it crashed on iPhone6 plus. #22

Open
iTA9178 opened this issue May 21, 2015 · 8 comments
Open

photo and it crashed on iPhone6 plus. #22

iTA9178 opened this issue May 21, 2015 · 8 comments

Comments

@iTA9178
Copy link

iTA9178 commented May 21, 2015

the delegate method return a capturedImage,and it's size 2448 * 2448 on iPhone6 plus device,cause memory waring then crash.Colud you help me or something advice?

  • (void)cameraController:(id)cameraController didFinishCapturingImage:(FastttCapturedImage *)capturedImage
@mdelmaestro
Copy link
Contributor

@iTA9178 Hi there!
News on this issue? Did you resolve the memory warning / crash?

@wayn
Copy link

wayn commented Jul 20, 2015

Remove the fullimage normalize worked. Code on the FastttCapturedImage+Process line63

@lauraskelton
Copy link
Contributor

Hi, thanks for letting us know! This seems to be working fine for us on iPhone 6 Plus, but if the normalize is problematic, you can always set normalizesImageOrientations = NO on your FastttCamera instance to disable this feature.

I'll also go through and see if we can optimize the memory usage of the code a bit more and see if we can improve performance here. Is it in the demo where you're seeing the problem, or in your own app?

@wayn
Copy link

wayn commented Jul 28, 2015

27ff6316-aa20-4a1e-8546-d69752029c50

The example project memory of take photo

@iTA9178
Copy link
Author

iTA9178 commented Jul 29, 2015

Here is the code to resolve the memory warning / crash in my project. Hope it will help other people has the same problem.

  • (void)cameraController:(id)cameraController didFinishCapturingImage:(FastttCapturedImage *)capturedImage {
    UIImage *scaledImage = [self imageByScalingToMaxSize:image];
    }

  • (UIImage *)imageByScalingToMaxSize:(UIImage *)sourceImage {
    if (sourceImage.size.width < ORIGINAL_MAX_WIDTH) return sourceImage;
    CGFloat btWidth = 0.0f;
    CGFloat btHeight = 0.0f;
    if (sourceImage.size.width > sourceImage.size.height) {
    btHeight = ORIGINAL_MAX_WIDTH;
    btWidth = sourceImage.size.width * (ORIGINAL_MAX_WIDTH / sourceImage.size.height);
    } else {
    btWidth = ORIGINAL_MAX_WIDTH;
    btHeight = sourceImage.size.height * (ORIGINAL_MAX_WIDTH / sourceImage.size.width);
    }
    CGSize targetSize = CGSizeMake(btWidth, btHeight);
    return [self imageByScalingAndCroppingForSourceImage:sourceImage targetSize:targetSize];
    }

  • (UIImage *)imageByScalingAndCroppingForSourceImage:(UIImage *)sourceImage targetSize:(CGSize)targetSize {
    UIImage *newImage = nil;
    CGSize imageSize = sourceImage.size;
    CGFloat width = imageSize.width;
    CGFloat height = imageSize.height;
    CGFloat targetWidth = targetSize.width;
    CGFloat targetHeight = targetSize.height;
    CGFloat scaleFactor = 0.0;
    CGFloat scaledWidth = targetWidth;
    CGFloat scaledHeight = targetHeight;
    CGPoint thumbnailPoint = CGPointMake(0.0,0.0);

    if (CGSizeEqualToSize(imageSize, targetSize) == NO)
    {
    CGFloat widthFactor = targetWidth / width;
    CGFloat heightFactor = targetHeight / height;

    if (widthFactor > heightFactor)
        scaleFactor = widthFactor; // scale to fit height
    else
        scaleFactor = heightFactor; // scale to fit width
    scaledWidth  = width * scaleFactor;
    scaledHeight = height * scaleFactor;
    
    // center the image
    if (widthFactor > heightFactor)
    {
        thumbnailPoint.y = (targetHeight - scaledHeight) * 0.5;
    }
    else
        if (widthFactor < heightFactor)
        {
            thumbnailPoint.x = (targetWidth - scaledWidth) * 0.5;
        }
    

    }

    UIGraphicsBeginImageContext(targetSize); // this will crop
    CGRect thumbnailRect = CGRectZero;
    thumbnailRect.origin = thumbnailPoint;
    thumbnailRect.size.width = scaledWidth;
    thumbnailRect.size.height = scaledHeight;

    [sourceImage drawInRect:thumbnailRect];

    newImage = UIGraphicsGetImageFromCurrentImageContext();
    if(newImage == nil) NSLog(@"could not scale image");

    //pop the context to get back to the default
    UIGraphicsEndImageContext();
    return newImage;
    }

@MrMatthewDavis
Copy link

I'm also having this issue. Using this in my own app and it works on every device except the 6+.

@lauraskelton
Copy link
Contributor

This is a known issue- the 6+ is tricky because the size of the images the camera returns really push the device to its memory limits. I'll try to find some time to look into resolving this and minimizing the memory footprint as much as we can here.

@euanSomo
Copy link

Any update on this?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

6 participants