There are three ways to get pictures on IOS
1 directly call camera to take pictures
2 Select from the album
3 Selecting from the Gallery
Uiimagepickercontroller is a system-provided interface for obtaining images and videos;
Use Uiimagepickercontroller class to obtain picture video;
It is broadly divided into the following steps:
- Initialize the Uiimagepickercontroller class
- Sets the data source type of the Uiimagepickercontroller instance (explained below);
- Setting up the Proxy
- If you need to make a picture change, set allowsediting =yes
There are three types of data sources:
enum { uiimagepickercontrollersourcetypephotolibrary,//From Gallery Uiimagepickercontrollersourcetypecamera,// From camera uiimagepickercontrollersourcetypesavedphotosalbum//From album};
When using these sources, it is best to check whether the following devices are supported;
if ([Uiimagepickercontroller Issourcetypeavailable:uiimagepickercontrollersourcetypecamera]) { NSLog (@ " Support Camera "); } if ([Uiimagepickercontroller issourcetypeavailable:uiimagepickercontrollersourcetypephotolibrary]) { NSLog (@ "Support Gallery"); } if ([Uiimagepickercontroller issourcetypeavailable:uiimagepickercontrollersourcetypesavedphotosalbum]) { NSLog (@ "Support photo gallery"); }
Call the camera to get the resource
-(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 properties need a pop-up call when you need to get a picture
[Self Presentviewcontroller:picker animated:yes completion:nil];
We also need agents to get the pictures we selected
Uiimagepickercontrollerdelegate
A total of three methods in the agent one of the 3.0 is obsolete, and there are only two of them we need.
-(void) Imagepickercontroller: (uiimagepickercontroller *) Picker Didfinishpickingmediawithinfo: ( nsdictionary *) info;
Called when the user chooses to finish;
-(void) Imagepickercontrollerdidcancel: (uiimagepickercontroller *) picker;
Called when the user cancels the selection;
-(void) Imagepickercontroller: ( Uiimagepickercontroller *) Picker Didfinishpickingmediawithinfo: (nsdictionary *) info;
The information selected is in info
Info is a dictionary
Get keys in dictionary
NSString *const Uiimagepickercontrollermediatype; Specifies the media type selected by the user (the last extension of the article) NSString *const Uiimagepickercontrolleroriginalimage, original picture nsstring *const uiimagepickercontrollereditedimage; modified Picture NSString * Const uiimagepickercontrollercroprect; Crop size nsstring *const uiimagepickercontrollermediaurl; Urlnsstring *const Uiimagepickercontrollerreferenceurl of the media ; urlnsstring *const of the original Uiimagepickercontrollermediametadata: This value only works when the data source is the camera.
More parameter references for Uiimagepickercontroller http://blog.sina.com.cn/s/blog_68edaff101019ppe.html
Agent in the function reference http://bbs.9ria.com/forum.php?mod=viewthread&tid=244453
Uiimagepickercontrollermediatype contains Kuttypeimage and Kuttypemovie.
Kuttypeimage contains
Const CFSTRINGREF kuttypeimage; abstract image Type const CFSTRINGREF kuttypejpeg; const CFSTRINGREF kUTTypeJPEG2000 ; const CFSTRINGREF kuttypetiff; const CFSTRINGREF kuttypepict; const CFSTRINGREF kuttypegif; const Cfstringref kuttypepng; const CFSTRINGREF kuttypequicktimeimage; const CFSTRINGREF Kuttypeappleicns Const CFSTRINGREF Kuttypebmp;const cfstringref Kuttypeico;
Kuttypemovie contains
Const CFSTRINGREF kuttypeaudiovisualcontent; abstract Sound Video const cfstringref kuttypemovie; abstract Media Format (sound and video) const Cfstringref kuttypevideo; only video no sound const cfstringref kuttypeaudio; only sound no video const CFSTRINGREF Kuttypequicktimemovie; const CFSTRINGREF kuttypempeg; const CFSTRINGREF kUTTypeMPEG4; Const CFSTRINGREF kUTTypeMP3; const CFSTRINGREF kuttypempeg4audio; const CFSTRINGREF kuttypeappleprotectedmpeg4audio;
IOS Get pictures (Photos, gallery, albums)