Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>In general there are two things I recommend you do. The first, consider using blocks to make your resizing and saving operations happen off the main thread (this requires iOS 4.0 and up). Your method would look something like this (off the top of my head and not compiled)</p> <pre><code>- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info { UIImage *image = [info objectForKey:UIImagePickerControllerOriginalImage]; dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{ CGRect screenBounds = [[UIScreen mainScreen] bounds]; CGFloat screenScale = [[UIScreen mainScreen] scale]; CGSize screenSize = CGSizeMake(screenBounds.size.width * screenScale, screenBounds.size.height * screenScale); UIGraphicsBeginImageContext(screenSize); [image drawInRect:CGRectMake(0,0,screenSize.width,screenSize.height)]; UIImage *newImage = UIGraphicsGetImageFromCurrentImageContext(); UIGraphicsEndImageContext(); NSUserDefaults *currentDefaults = [NSUserDefaults standardUserDefaults]; [currentDefaults setObject:UIImagePNGRepresentation(newImage) forKey:@"newImageKey"]; [currentDefaults synchronize]; }); [popoverController dismissPopoverAnimated:YES]; [picker dismissModalViewControllerAnimated:YES]; } </code></pre> <p>The second thing I strongly recommend is to not store the resulting image in NSUserDefaults. NSUserDefaults is only intended to be a small key-value store. If you're going to store images, store them on disk using NSFileManager and store the path as the value in NSUserDefaults. </p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload