daily pastebin goal
5%
SHARE
TWEET

Untitled

a guest May 20th, 2018 98 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. – imagePickerController:didFinishPickingImage:editingInfo:
  2.    
  3. - (void) imagePickerController:(UIImagePickerController*)picker didFinishPickingImage:(UIImage*)img editingInfo:(NSDictionary*)editInfo
  4. {
  5.  
  6.     image.image = img;
  7.     [[picker parentViewController] dismissModalViewControllerAnimated:YES];
  8.  
  9.  
  10. }
  11.    
  12. imagePickerController:didFinishPickingImage:editingInfo:
  13.    
  14. @interface MyClass : UIViewController <UINavigationControllerDelegate, UIImagePickerControllerDelegate> {
  15. UIImagePickerController*    imagePicker;
  16. }
  17. @property(nonatomic,retain) UIImagePickerController* imagePicker;
  18.  
  19. - (IBAction) takePicture:(id)sender;
  20.  
  21. @end
  22.    
  23. #import <MobileCoreServices/UTCoreTypes.h>
  24. ...
  25. @synthesize imagePicker = _imagePicker;
  26. ...
  27.  
  28. - (void) takePicture:(id)sender
  29. {
  30.         if (!_imagePicker) {
  31.             self.imagePicker = [[UIImagePickerController alloc] init];
  32.             self.imagePicker.delegate = self;
  33.         }
  34.  
  35.         if ([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera]) {
  36.             self.imagePicker.sourceType = UIImagePickerControllerSourceTypeCamera;
  37.             NSArray* mediaTypes = [UIImagePickerController availableMediaTypesForSourceType:UIImagePickerControllerSourceTypeCamera];
  38.             self.imagePicker.mediaTypes = mediaTypes;
  39.         } else {
  40.             self.imagePicker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
  41.             self.imagePicker.allowsImageEditing = YES;
  42.         }
  43.  
  44.     [self presentModalViewController:self.imagePicker animated:YES];
  45. }
  46.    
  47. - (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
  48. {
  49.     [[picker parentViewController] dismissModalViewControllerAnimated:YES];
  50.  
  51.     // MediaType can be kUTTypeImage or kUTTypeMovie. If it's a movie then you
  52.     // can get the URL to the actual file itself. This example only looks for images.
  53.     //  
  54.     NSString* mediaType = [info objectForKey:UIImagePickerControllerMediaType];
  55.     // NSString* videoUrl = [info objectForKey:UIImagePickerControllerMediaURL];
  56.  
  57.     // Try getting the edited image first. If it doesn't exist then you get the
  58.     // original image.
  59.     //
  60.     if (CFStringCompare((CFStringRef) mediaType, kUTTypeImage, 0) == kCFCompareEqualTo) {      
  61.         UIImage* picture = [info objectForKey:UIImagePickerControllerEditedImage];
  62.         if (!picture)
  63.             picture = [info objectForKey:UIImagePickerControllerOriginalImage];    
  64.  
  65.             // **You can now do something with the picture.
  66.     }
  67.     self.imagePicker = nil;
  68. }
  69.  
  70. - (void)imagePickerControllerDidCancel:(UIImagePickerController *)picker
  71. {
  72.     [[picker parentViewController] dismissModalViewControllerAnimated:YES];
  73.     self.imagePicker = nil;
  74. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top