FastttCamera icon indicating copy to clipboard operation
FastttCamera copied to clipboard

photo and it crashed on iPhone6 plus.

Open iTA9178 opened this issue 9 years ago • 8 comments

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<FastttCameraInterface>)cameraController didFinishCapturingImage:(FastttCapturedImage *)capturedImage

iTA9178 avatar May 21 '15 03:05 iTA9178

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

mdelmaestro avatar Jul 06 '15 08:07 mdelmaestro

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

wayn avatar Jul 20 '15 09:07 wayn

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?

lauraskelton avatar Jul 20 '15 16:07 lauraskelton

27ff6316-aa20-4a1e-8546-d69752029c50

The example project memory of take photo

wayn avatar Jul 28 '15 07:07 wayn

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; }

iTA9178 avatar Jul 29 '15 04:07 iTA9178

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

MrMatthewDavis avatar Oct 14 '15 22:10 MrMatthewDavis

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.

lauraskelton avatar Oct 14 '15 23:10 lauraskelton

Any update on this?

euanSomo avatar Feb 15 '16 09:02 euanSomo