How to call a local photo album, Camera

Source: Internet
Author: User

 1, judging whether the system supports the camera [Uiimagepickercontroller issourcetypeavailable:uiimagepickercontrollersourcetypecamera] 2. Create album view Controller object Uiimagepickercontroller *imagepickercontroller = [[Uiimagepickercontroller alloc] init];3, Set SourceType (resource type) Imagepickercontroller.sourcetype = uiimagepickercontrollersourcetypecamera;// Camera Imagepickercontroller.sourcetype = uiimagepickercontrollersourcetypephotolibrary;// Photo Gallery Imagepickercontroller.sourcetype = uiimagepickercontrollersourcetypesavedphotosalbum;//saved picture 4, Set pop-up animations (optional) Imagepickercontroller.modaltransitionstyle = Uimodaltransitionstylecoververtical;5, Set whether to allow editing of picture imagepickercontroller.allowsediting = yes;6, set proxy (uiimagepickercontrollerdelegate) Imagepickercontroller.delegate = self;7, Implementing proxy method: Get picture-(void) Imagepickercontroller: (Uiimagepickercontroller *) picker Didfinishpickingmediawithinfo: (nsdictionary *) info{     [Picker dismissViewControllerAnimated :yes completion:nil];   //Get pictures      UIImage *image =[Info objectforkey:uiimagepickercontrolleroriginalimage];} Cancel click-(void) Imagepickercontrollerdidcancel: (Uiimagepickercontroller *) picker{    [self  dismissviewcontrolleranimated:yes completion:^{}];} 8. Save picture to album Uiimagewritetosavedphotosalbum (image, Self, @selector (image:didFinishSavingWithError:contextInfo:), nil) ;//image: The picture Uimage object to save,-(void) Image: (UIImage *) Imagedidfinishsavingwitherror: (Nserror *) error   ContextInfo: (void *) contextinfo{//if error==null, indicates that the picture was saved successfully}  specific code:-(void) Viewdidload {
[Super Viewdidload];
UIButton *btn = [UIButton buttonwithtype:uibuttontypecustom];
Btn.frame = CGRectMake (10, 50, 80, 80);
Btn.backgroundcolor = [Uicolor Redcolor];    [Btn addtarget:self Action: @selector (Showpicker) forcontrolevents:uicontroleventtouchupinside]; [Self.view addsubview:btn];}
-(void) showpicker{
Uiimagepickercontroller *imagepicker = [[Uiimagepickercontroller alloc]init];
Imagepicker.sourcetype = 2;//Setting type (0 for Call album, 1 for pop-up camera)
Imagepicker.allowsediting = yes;//Whether to allow editing, default No, set to YES, click on the picture will go to the editing interface (cropping)
Imagepicker.delegate = self;//set agent [self presentviewcontroller:imagepicker animated:yes completion:nil];//pop-up album/Camera
}
Proxy method called after selecting a picture
-(void) Imagepickercontroller: (Uiimagepickercontroller *) Picker Didfinishpickingmediawithinfo: (NSDictionary< NSString *,id> *) info{
NSLog (@ "%@", info);
UIImage *image = info[@ "Uiimagepickercontrollereditedimage"];//get Pictures
Uiimageview *imageview = [[Uiimageview alloc]initwithimage:image];
Imageview.frame = CGRectMake (40, 150, 100, 100);     [Self.view Addsubview:imageview]; [Self Dismissviewcontrolleranimated:yes completion:nil];//disappears Imagepicker}

How to call a local photo album, Camera

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.