IOS image retrieval (photo taking, image library, and album)

Source: Internet
Author: User

IOS image retrieval (photo taking, image library, and album)

There are three methods for iOS to get images

1. directly call the camera to take a photo

2. Select from album

3. Select from Image Library


UIImagePickerController is an interface provided by the system to obtain images and videos;

Use the UIImagePickerController class to obtain images and videos;

The procedure is as follows:

Initialize the UIImagePickerController class and set the data source type of the UIImagePickerController instance (as described below). Set the proxy to set allowsEditing = yes if you need to modify the image. There are three data source types:
Enum {UIImagePickerControllerSourceTypePhotoLibrary, // from Image Library UIImagePickerControllerSourceTypeCamera, // from camera UIImagePickerControllerSourceTypeSavedPhotosAlbum/from album };


When using these sources, it is best to check whether the following devices are supported;

If ([UIImagePickerController isSourceTypeAvailable: available]) {NSLog (@ "camera supported");} if ([UIImagePickerController isSourceTypeAvailable: available]) {NSLog (@ "");} if ([UIImagePickerController isSourceTypeAvailable: UIImagePickerControllerSourceTypeSavedPhotosAlbum]) {NSLog (@ "Photo Library Supported ");}

Call the camera to obtain resources

- (void)viewDidLoad {    [super viewDidLoad];    picker = [[UIImagePickerController alloc]init];    picker.view.backgroundColor = [UIColor orangeColor];    UIImagePickerControllerSourceType sourcheType = UIImagePickerControllerSourceTypeCamera;    picker.sourceType = sourcheType;    picker.delegate = self;    picker.allowsEditing = YES;}

The above is just an example of UIImagePickerController and Its Attributes. You need to call it in a pop-up window when you need to obtain the image.

[self presentViewController:picker animated:YES completion:nil];

We also need a proxy to retrieve the selected image.

UIImagePickerControllerDelegate

There are three methods in the proxy, one of which is 3.0 obsolete, and there are only two

-(Void) imagePickerController :( UIImagePickerController *) picker didFinishPickingMediaWithInfo :( NSDictionary *) info;

Called after user selection is complete;

-(Void) imagePickerControllerDidCancel :( UIImagePickerController *) picker;

Called when the user cancels the selection;

-(Void) imagePickerController :( UIImagePickerController *) picker didFinishPickingMediaWithInfo :( NSDictionary *) info;

The selected information is in info.

Info is a dictionary

Keys in the dictionary

NSString * const UIImagePickerControllerMediaType; specifies the selected media type (expanded at the end of the article) NSString * const category; original image NSString * const category; Modified Image NSString * const UIImagePickerControllerCropRect; crop NSString * const UIImagePickerControllerMediaURL; media URLNSString * const region; original URLNSString * const UIImagePickerControllerMediaMetadata; this value is valid only when the data source is a camera.


UIImagePickerController for more parameters refer to http://blog.sina.com.cn/s/blog_68edaff101019ppe.html

In the proxy function reference http://bbs.9ria.com/forum.php? Mod = viewthread & tid = 244453.




UIImagePickerControllerMediaType contains

KUTTypeImage inclusion

Const uses kUTTypeImage; the Abstract Image Type const CFStringRef kUTTypeJPEG; const CFStringRef kuttype2000; const CFStringRef kUTTypeTIFF; const CFStringRef kUTTypePICT; const CFStringRef comment; const has been added; const CFStringRef kUTTypeAppleICNS const CFStringRef kUTTypeBMP; const CFStringRef kUTTypeICO;

KUTTypeMovie inclusion

Const CFStringRef kUTTypeAudiovisualContent; abstract sound video const CFStringRef kUTTypeMovie; abstract media format (sound and video) const CFStringRef kUTTypeVideo; only the video has no sound const CFStringRef kUTTypeAudio; only video const CFStringRef kUTTypeQuickTimeMovie; const CFStringRef kUTTypeMPEG; const CFStringRef kUTTypeMPEG4; const CFStringRef kUTTypeMP3; const CFStringRef cursor;


Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.