Memory Warning UIImagepickerController IOS 7

后端 未结 3 1593
借酒劲吻你
借酒劲吻你 2020-12-25 08:20

Could anybody help me with this issue I\'m a bit new to objective c and iOS. I\'ve been working on it but I can\'t figure out how to fix the problem, My app is really simpl

3条回答
  •  长发绾君心
    2020-12-25 09:14

    You're on the right track with your fixRotation method. However, you should also resize the image. Otherwise, the image will be huge, ~30 MB (depending on device).

    Checkout this blog post on how to resize images correctly. Specifically, the UIImage category files you want are these:

    UIImage+Resize.h

    UIImage+Resize.m

    It's also a good idea to do this on a background thread. Something like this

    - (void)imagePickerController:(UIImagePickerController *)imagePicker didFinishPickingMediaWithInfo:(NSDictionary *)info
    {
        // Dismiss the image picker first to free its memory
        [self dismissViewControllerAnimated:YES completion:nil];
    
        UIImage *originalImage = info[UIImagePickerControllerOriginalImage];
    
        if (!originalImage)
            return;
    
        // Optionally set a placeholder image here while resizing happens in background
    
        dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
    
            // Set desired maximum height and calculate width
            CGFloat height = 640.0f;  // or whatever you need
            CGFloat width = (height / originalImage.size.height) * originalImage.size.width;
    
            // Resize the image
            UIImage * image = [originalImage resizedImage:CGSizeMake(width, height) interpolationQuality:kCGInterpolationDefault];
    
            // Optionally save the image here...
    
            dispatch_async(dispatch_get_main_queue(), ^{
                // ... Set / use the image here...
            });           
        });
    }
    

提交回复
热议问题