ios-Camera, photo album

Source: Internet
Author: User

1 //2 //VIEWCONTROLLER.M3 //ios_0301_ albums and Cameras4 //5 //Created by Ma C on 16/3/1.6 //copyright©2016 Blog Technology. All rights reserved.7 //8 9 #import "ViewController.h"Ten  One @interfaceViewcontroller () <UIActionSheetDelegate,UIImagePickerControllerDelegate,UINavigationControllerDelegate> A  -@property (nonatomic, strong) Uiimageview *Chooseimgview; -@property (nonatomic, strong) UIButton *Btnopencamera; the  - @end -  - @implementationViewcontroller +  -- (void) Viewdidload { + [Super Viewdidload]; A      atSelf.chooseimgview = [[Uiimageview alloc] Initwithframe:cgrectmake ( -, -, -, -)]; -Self.chooseImgView.backgroundColor =[Uicolor Cyancolor]; - [Self.view AddSubview:self.chooseImgView]; -Self.btnopencamera =[UIButton Buttonwithtype:uibuttontypecustom]; -[Self.btnopencamera Setframe:cgrectmake ( -, -, $, -)]; - [Self.btnopencamera setbackgroundcolor:[uicolor redcolor]; in[Self.btnopencamera Settitle:@"Photo Album Camera"Forstate:uicontrolstatenormal]; - [Self.view AddSubview:self.btnOpenCamera]; to      + [Self.btnopencamera addtarget:self Action: @selector (Opencamera) forcontrolevents:uicontroleventtouchupinside] ; - } the /* * Uiimagepickercontroller (Photo picker) $ ability to open camera or album according to different instructionsPanax Notoginseng PS: - 1. Implement two protocols when using the picture picker the uiimagepickercontrollerdelegate + uinavigationcontrollerdelegate A 2. Determine if the current device has a camera the   +  */ -  $- (void) Opencamera $ { -NSLog (@"Open Album"); -      theUiactionsheet *actionsheeet = [[Uiactionsheet alloc] Initwithtitle:@"Open System camera | albums" Delegate: Self Cancelbuttontitle:@"Cancel"Destructivebuttontitle:@"Camera"Otherbuttontitles:@"albums", nil]; -     Wuyi      the [Actionsheeet ShowInView:self.view]; -      Wu } -  About- (void) Actionsheet: (Uiactionsheet *) Actionsheet Clickedbuttonatindex: (nsinteger) Buttonindex $ { -     Switch(buttonindex) { -          Case 0: -         { ANSLog (@"Camera"); +             //set up Picture Picker theUiimagepickercontroller *imgpicker =[[Uiimagepickercontroller alloc] init]; -             //Set up proxy $Imgpicker.Delegate=Self ; the             //Set the picture Picker type theImgpicker.sourcetype =Uiimagepickercontrollersourcetypecamera; the             //whether to allow picture editing theImgpicker.allowsediting =YES; -             //wake-Up camera in [self presentviewcontroller:imgpicker animated:yes completion:nil]; the         } the              Break; About          Case 1: the         { theNSLog (@"albums"); the             //set up Picture Picker +Uiimagepickercontroller *imgpicker =[[Uiimagepickercontroller alloc] init]; -             //Set up proxy theImgpicker.Delegate=Self ;Bayi             //Set the picture Picker type theImgpicker.sourcetype =uiimagepickercontrollersourcetypephotolibrary; the             //whether to allow picture editing -Imgpicker.allowsediting =YES; -             //wake-Up camera the [self presentviewcontroller:imgpicker animated:yes completion:nil]; the  the         } the              Break; -              the         default: the              Break; the     }94      the } the  the- (void) Imagepickercontroller: (Uiimagepickercontroller *) Picker Didfinishpickingmediawithinfo: (NSDictionary<NSString *,ID> *) Info98 { About     //to complete the operation of getting a picture -NSLog (@"%@", info);101     //get the edited picture102UIImage *chooseimage = [Info objectforkey:@"Uiimagepickercontrollereditedimage"];103NSString *imagename = [Info objectforkey:@"Uiimagepickercontrollerreferenceurl"];104NSLog (@"%@", imageName); the     106Self.chooseImgView.image =Chooseimage;107     108     109     //Take the picture out of the system album and save it in the Shahe theNSString *homepath = [Nshomedirectory () stringByAppendingPathComponent:@"/documents"];111NSString *realpath = [HomePath stringbyappendingpathcomponent:[nsstring stringWithFormat:@"%d", Arc4random ()% +]]; the     113NSLog (@"%@", Realpath); the[UIImageJPEGRepresentation (Chooseimage,1.0f) Writetofile:realpath Atomically:yes]; the      the [self dismissviewcontrolleranimated:yes completion:nil];117     118 }119  -- (void) didreceivememorywarning {121 [Super didreceivememorywarning];122     //Dispose of any resources the can be recreated.123 }124  the @end

ios-camera, 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.