Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Don't worry about the memory warning. If you're using <code>UIImagePickerController</code> on iPhone 4S or older devices, you'll typically get this warning, and you can't do much about it.</p> <p>What's important is that you need to make sure you're resizing the image appropriately via your delegate method for <code>imagePickerController:didFinishPickingMediaWithInfo:</code>. If you try to save and use (such as displaying in <code>UIImageView</code>) the <em>original image</em>, you will crash on these older devices due to memory pressure.</p> <p>See this <a href="http://vocaro.com/trevor/blog/2009/10/12/resize-a-uiimage-the-right-way/" rel="nofollow">excellent blog post</a> for a discussion on the correct way to resize a <code>UIImage</code>.</p> <p>Specifically, you will find this category to be helpful for resizing images correctly:</p> <p><a href="http://vocaro.com/trevor/blog/wp-content/uploads/2009/10/UIImage+Resize.h" rel="nofollow">UIImage+Resize.h</a></p> <p><a href="http://vocaro.com/trevor/blog/wp-content/uploads/2009/10/UIImage+Resize.m" rel="nofollow">UIImage+Resize.m</a></p> <p>If you already use another method that works, great. Otherwise, this method works very well.</p> <p>Using said category methods, here's an example of <code>imagePickerController:didFinishPickingMediaWithInfo:</code> using GCD to do the resizing on a background thread:</p> <pre><code>- (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; CGFloat width = (height / self.size.height) * self.size.width; UIImage * image = [originalImage resizedImage:CGSizeMake(width, height) interpolationQuality:kCGInterpolationDefault]; // Save and use this image }); } </code></pre>
    singulars
    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. This table or related slice is empty.
    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