Uiimagepickercontroller get pictures from photos, galleries, albums

Source: Internet
Author: User

Uiimagepickercontroller get pictures from photos, galleries, albums
There are three ways to get pictures from IOS:
1. Directly call the camera to take pictures
2. Select from the album
3. Select from the Gallery
Uiimagepickercontroller is a system-provided interface for obtaining images and videos;
Use the Uiimagepickercontroller class to obtain picture video, broadly divided into the following steps:
1. Initialize the Uiimagepickercontroller class;
2. Set the data source type of the Uiimagepickercontroller instance (explained below);
3. Set up proxy;
4. If you need to make picture changes, set allowsediting =yes.
There are three types of data sources:
enum {uiimagepickercontrollersourcetypephotolibrary,//From Gallery Uiimagepickercontrollersourcetypecamera,//From camera UIImage Pickercontrollersourcetypesavedphotosalbum//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]) {NS    Log (@ "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 that is selected is in info, and info is a dictionary.
Keys in the 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, cutting size nsstring *const uiimagepickercontrollermediaurl; urlnsstring *const of media Uiimagepickercontrollerreferenceurl; The original urlnsstring *const Uiimagepickercontrollermediametadata; This value only works when the data source is the camera.
Uiimagepickercontroller more parameters refer to here.
The function reference in the agent is here.
Uiimagepickercontrollermediatype contains Kuttypeimage and Kuttypemovie.
Kuttypeimage contains:
Const CFSTRINGREF Kuttypeimage; Abstract image Type Const CFSTRINGREF kuttypejpeg; const CFSTRINGREF kUTTypeJPEG2000; Const cfstring Ref Kuttypetiff; const CFSTRINGREF kuttypepict; const CFSTRINGREF kuttypegif; const CFSTRINGREF kuttypepng; Const CFST Ringref kuttypequicktimeimage; const CFSTRINGREF Kuttypeappleicns const CFSTRINGREF kuttypebmp;const CFStringRef KUTTYP EICo;
Kuttypemovie contains:
Const CFSTRINGREF kuttypeaudiovisualcontent; abstract Sound video const CFSTRINGREF Kuttypemovie; Abstract Media Format (sound and video) const CFSTRINGREF KU  Ttypevideo; only video no voice 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;

Uiimagepickercontroller get pictures from photos, galleries, albums

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.