iOS dev-ios call camera call album "Save picture to local album"

Source: Internet
Author: User

Set up the head agent
<uinavigationcontrollerdelegate, uiimagepickercontrollerdelegate>
1. Calling the camera

Detect if a front-facing camera is available

- (BOOL) isfrontcameraavailable{    return  [Uiimagepickercontroller iscameradeviceavailable : Uiimagepickercontrollercameradevicefront];}

Detect if the rear camera is available

- (BOOL) isrearcameraavailable{    return  [Uiimagepickercontroller iscameradeviceavailable: Uiimagepickercontrollercameradevicerear];}

Call camera

///Call Camera- (void) persentimagepicker{if(!_imagepickerg) {        ///Initializing the camera_imagepickerg =[[Uiimagepickercontroller alloc]init]; ///Agent_imagepickerg.Delegate=Self ; }        //whether the front camera is available    if([self isfrontcameraavailable]) {_imagepickerg.sourcetype=Uiimagepickercontrollersourcetypecamera; }    //whether the rear camera is available    Else if([self isfirstresponder]) {_imagepickerg.sourcetype=Uiimagepickercontrollersourcetypecamera; }    Else{[Svprogresshud showerrorwithstatus:@"no camera available ~"]; return; }    ///allow cropping after taking pictures_imagepickerg.allowsediting =YES; [Self.navigationcontroller Presentviewcontroller:_imagepickerg Animated:yes completion:nil];}
2. Call Album
///calling a local album- (void) persentimagepicker{if(!_imagepickerg) {        ///Initializing the camera_imagepickerg =[[Uiimagepickercontroller alloc]init]; ///Agent_imagepickerg.Delegate=Self ; }    ///albums_imagepickerg.sourcetype =uiimagepickercontrollersourcetypephotolibrary;_imagepickerg.allowsediting=YES; [Self.navigationcontroller Presentviewcontroller:_imagepickerg Animated:yes completion:nil];}
3. Agent Events
/// deselect picture (take photo)-(void) Imagepickercontrollerdidcancel: (Uiimagepickercontroller *) picker{    [ Picker Dismissviewcontrolleranimated:yes Completion:nil];}
/// Select the picture to complete (from the album or take a photo)-(void) Imagepickercontroller: (Uiimagepickercontroller *) picker Didfinishpickingmediawithinfo: (nsdictionary<nsstring *,ID> *) info{    *image = [Info objectforkey:uiimagepickercontrolleroriginalimage];///original     //Get the picture    after trimming UIImage *imageup = [info objectforkey:uiimagepickercontrollereditedimage]; }
4. Save the picture to a local
/// Save picture to local album -(void) Imagetopicsave: (UIImage *) image{    uiimagewritetosavedphotosalbum (image , Self, @selector (image:didFinishSavingWithError:contextInfo:), nil);} -(void) Image: (UIImage *) image didfinishsavingwitherror: (nserror *) error contextinfo: (void *) contextinfo{    if (Error = = nil)            {    }else{         // the picture could not be saved locally     }}

iOS dev-ios call camera call album "Save picture to local album"

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.