UIImagePickerController run out of memory with camera source

前端 未结 2 573
一整个雨季
一整个雨季 2021-02-03 16:39

I got a big performance issue using UIImagePickerController and saving the image on disk. I can\'t figure out what I am doing wrong. Here is my code:



        
相关标签:
2条回答
  • 2021-02-03 16:43

    I had a similar issue. The way I got round it was to handle the image from the picker in a seperate thread. My problem was the main thread handling my app/UI was crashing out when trying to close the picker and handle the image:

    - (void)imagePickerController:(UIImagePickerController *)picker
        didFinishPickingImage:(UIImage *)image
                  editingInfo:(NSDictionary *)editingInfo
    {
        [[picker parentViewController] dismissModalViewControllerAnimated:YES];
    
        NSLog(@"picker did finish");
        [NSThread detachNewThreadSelector:@selector(useImage:) toTarget:self withObject:image];
    
    }
    
    0 讨论(0)
  • 2021-02-03 16:52

    Your problem might be due to you taking the original image.

    The original image from the camera has a resolution of around 1200x1400, which is a lot of memory and will cause the device to crash if you try making a picture out of it (it will run out of memory).

    I would suggest resizing the image to be smaller (the native 320x480).

    0 讨论(0)
提交回复
热议问题