First, the basic properties
UIKit-Uiimagepickercontroller
Cameracapturemode distinguish between a photo or a video
Distinguish camera video Cameracapturemode:
Video: Uiimagepickercontrollercameracapturemodevideo
Photo: Uiimagepickercontrollercameracapturemodephoto
distinguish between Select Camera albums sourcetype
Webcam: Uiimagepickercontrollersourcetypecamera
Albums: Uiimagepickercontrollersourcetypephotolibrary
Albums: Uiimagepickercontrollersourcetypesavedphotosalbum
Differentiate front and rear camera cameradevice
Front Camera: Uiimagepickercontrollercameradevicefront
Rear-facing camera: uiimagepickercontrollercameradevicerear
Set whether control controls are displayed
Showscameracontrols Default Display control controls
Set up a photo
Takepicture
Video
Startvideocapture
Stopvideocapture
Set up Video definition videos
Set Flash Cameraflashmode
1, the Uiimagepickercontrollercameraflashmodeoff closed
2, Uiimagepickercontrollercameraflashmodeauto Auto Default
3, Uiimagepickercontrollercameraflashmodeon Open
Uiimagepickercontrollerqualitytypehigh
Uiimagepickercontrollerqualitytypemedium
Uiimagepickercontrollerqualitytypelow
uiimagepickercontrollerqualitytype640x480
uiimagepickercontrollerqualitytypeiframe1280x720
uiimagepickercontrollerqualitytypeiframe960x540
Videomaximumduration setting the maximum duration of the video
Cameraoverlayview Setting the overlay view of the Call Camera view page
Set the shape of the photo page Cameraviewtransform
Agent
????? Need to import two agents
Uinavigationcontrollerdelegate, Uiimagepickercontrollerdelegate
After the acquisition is done, the call does not distinguish between taking a picture or photographing the same method.
-(void) Imagepickercontroller: (Uiimagepickercontroller *) Picker Didfinishpickingmediawithinfo: (NSDictionary< NSString *,id> *) info;
Call when the collection is canceled
-(void) Imagepickercontrollerdidcancel: (Uiimagepickercontroller *) picker;
Save picture to album Uiimagewritetosavedphotosalbum:
Callback after saving is complete
-(void) Image: (UIImage *) image didfinishsavingwitherror: (nserror *) error ContextInfo: (void *) ContextInfo
Code examples,
Import Frame: #import<MobileCoreServices/MobileCoreServices.h>#import"uiview+transfrom.h"macro definition:#definescreen_bounds [UIScreen mainscreen].bounds//Screen Size#defineScreen_width cgrectgetwidth ([UIScreen mainscreen].bounds)//Screen Width#defineScreen_height cgrectgetheight ([UIScreen mainscreen].bounds)//Screen HeightGlobal variables and import Agents @interface Viewcontroller ()<UINavigationControllerDelegate,UIImagePickerControllerDelegate>{UILabel*showtypelabel;//controls that display photos or videosBOOL Ismovie;//Judging the basis of photographic cameraUiimageview*showmediaview;//view showing the results of a photo recording} @end- (void) viewdidload {[Super viewdidload]; Self.edgesforextendedlayout=Uirectedgenone; Self.view.backgroundColor=[Uicolor Greencolor]; Uiswitch*mediaswitch = [[Uiswitch alloc]initwithframe:cgrectmake (screen_width- -, -, -, -) ]; [Mediaswitch addtarget:self Action: @selector (Changemdiatype:) forcontrolevents:uicontroleventvaluechanged]; [Self.view Addsubview:mediaswitch]; Showtypelabel= [[UILabel alloc]initwithframe:cgrectmake (Cgrectgetminx (Mediaswitch.frame), Cgrectgetminy (Mediaswitch.frame)- +, -, -)]; Showtypelabel.textalignment=Nstextalignmentcenter; Showtypelabel.text=@"Take Pictures"; Showtypelabel.textcolor=[Uicolor Lightgraycolor]; Showtypelabel.backgroundcolor=[Uicolor Cyancolor]; [Self.view Addsubview:showtypelabel]; Showmediaview= [[Uiimageview alloc]initwithframe:cgrectmake ( -, -, -, -)]; Showmediaview.backgroundcolor=[Uicolor Orangecolor]; [Self.view Addsubview:showmediaview]; UIButton*button =[UIButton Buttonwithtype:uibuttontypecustom]; Button.frame= CGRectMake ( -, -, -, -); [Button Settitle:@"Camera"Forstate:uicontrolstatenormal]; Button.backgroundcolor=[Uicolor Browncolor]; [Button addtarget:self action: @selector (doit:) forcontrolevents:uicontroleventtouchupinside]; [Self.view Addsubview:button]; } The trigger method of the switch here to add special effects to label label text- (void) Changemdiatype: (Uiswitch *) sender{[Showtypelabel rotation]; Showtypelabel.text= Sender.ison! = YES?@"Take Pictures":@"Video"; To decide whether it's a video or a photo Ismovie=Sender.ison; } button's Trigger event- (void) doit: (UIButton *) sender{Uiimagepickercontroller*pickercontroller =[[Uiimagepickercontroller alloc]init]; Pickercontroller.Delegate=Self ;//Select a camera device//The default is to select albumsPickercontroller.sourcetype =Uiimagepickercontrollersourcetypecamera; if(Ismovie = =YES) { //Select media Type the default is to take a picture of a photo when you do not select the media type does not crash because the default setting is Kuttypeimage, included in the framework of mobilecoreservices this is not the type of string in OC To cast//record video type to select Kuttypemovie it contains audio videoPickercontroller.mediatypes = @[(NSString *) Kuttypemovie]; //Set recording default photo ********** Be sure to select the type of media before the program crashesPickercontroller.cameracapturemode =Uiimagepickercontrollercameracapturemodevideo; } [Self Presentviewcontroller:pickercontroller animated:yes completion:nil]; }- (void) Imagepickercontroller: (Uiimagepickercontroller *) Picker Didfinishpickingmediawithinfo: (NSDictionary<NSString *,id> *) info{if([Info[uiimagepickercontrollermediatype] isequaltostring: (NSString *) {Kuttypemovie]) {NSLog (@"finished recording ."); NSString*path = (NSString *) [Info[uiimagepickercontrollermediaurl] path]; Uisavevideoatpathtosavedphotosalbum (path, self, @selector (video:didFinishSavingWithError:contextInfo:), nil); } if([Info[uiimagepickercontrollermediatype] isequaltostring: (NSString *) {Kuttypeimage]) {NSLog (@"It's done ."); shot Pictures NSLog (@"%@", Info[uiimagepickercontrolleroriginalimage]); UIImage*finishimage =Info[uiimagepickercontrolleroriginalimage]; Showmediaview.image=Nil; Showmediaview.image=Finishimage; //turn the picture into binary and save it.NSData *imagedata = uiimagejpegrepresentation (Finishimage,0.1); NSData*imagedata1 =uiimagepngrepresentation (finishimage); //How to save photos to an albumUiimagewritetosavedphotosalbum (Finishimage, Self, @selector (image:didFinishSavingWithError:contextInfo:), nil ); } [self Dismissviewcontrolleranimated:yes completion:nil];}//called after the video is saved to the album- (void) Video: (NSString *) Videopath didfinishsavingwitherror: (nserror *) Error ContextInfo: (void*) contextinfo{Avplayer*player =[Avplayer Playerwithurl:[nsurl Fileurlwithpath:videopath]; Avplayerviewcontroller*VC =[[Avplayerviewcontroller alloc] init]; Vc.player=player; [Self PRESENTVIEWCONTROLLER:VC animated:yes completion:nil]; [Vc.player play]; }//Save the photo to the album successfully call this method- (voidImage: (UIImage *) image didfinishsavingwitherror: (nserror *) Error ContextInfo: (void*) contextinfo{NSLog (@"saved successfully"); }- (void) Imagepickercontrollerdidcancel: (Uiimagepickercontroller *) picker{NSLog (@"Cancel"); [Self Dismissviewcontrolleranimated:yes completion:nil];}
iOS video capture