Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>You may know how to present the image picker:</p> <pre><code>UIImagePickerController *picker = [[UIImagePickerController alloc] init]; picker.delegate = self; picker.mediaTypes = [UIImagePickerController availableMediaTypesForSourceType:UIImagePickerControllerSourceTypePhotoLibrary]; [viewController presentModalViewController:picker animated:YES]; </code></pre> <p>With the above the viewController implements the UIImagePickerControllerDelegate and make sure you implement this function:</p> <pre><code>- (void)imagePickerController:(UIImagePickerController *)returnedPicker didFinishPickingMediaWithInfo:(NSDictionary *)info </code></pre> <p>and</p> <pre><code>- (void)imagePickerControllerDidCancel:(UIImagePickerController *)returnedPicker </code></pre> <p>The first method is called when user has picked a photo. In this method you get the image using:</p> <pre><code>UIImage *image = [info objectForKey:UIImagePickerControllerOriginalImage]; </code></pre> <p>To write this to a file you can make it a JPEG or a PNG. If a JPEG you may do this:</p> <pre><code>[UIImageJPEGRepresentation(image, 1.0) writeToFile:filename atomically:YES]; </code></pre> <p>You just need to set the filename. </p> <pre><code>NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES); NSString *docsDir = [paths objectAtIndex:0]; NSString *filename = [docsDir stringByAppendingPathComponent:@"myFilename.jpg"]; </code></pre> <p>To get the image back into a UIImage you do this:</p> <pre><code>NSData *data = [NSData dataWithContentsOfFile:filename; if(data != nil) UIImage *image = [UIImage imageWithData:data]; </code></pre>
 

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