Static methods for 1.UIImagePickerController:
Imagepicker = [[Uiimagepickercontroller alloc]init];
Uiimagepickercontroller static method to determine whether the device supports camera/Photo Library/album function
/*
typedef ns_enum (Nsinteger, Uiimagepickercontrollersourcetype) {
Uiimagepickercontrollersourcetypephotolibrary,
Uiimagepickercontrollersourcetypecamera,
Uiimagepickercontrollersourcetypesavedphotosalbum
};
*/
BOOL iscamerasupport = [Uiimagepickercontroller Issourcetypeavailable:uiimagepickercontrollersourcetypecamera];
NSLog (@ "Support camera:%d", iscamerasupport);
Uiimagepickercontroller static method to determine if the device supports front-facing/rear-facing cameras
/*
typedef ns_enum (Nsinteger, Uiimagepickercontrollercameradevice) {
Uiimagepickercontrollercameradevicerear,
Uiimagepickercontrollercameradevicefront
};
*/
BOOL isrearsupport = [Uiimagepickercontroller iscameradeviceavailable:uiimagepickercontrollercameradevicerear];
NSLog (@ "Rear support:%d", isrearsupport);
Uiimagepickercontroller static method to determine if the device supports front camera flash/rear camera flash
/*
typedef ns_enum (Nsinteger, Uiimagepickercontrollercameradevice) {
Uiimagepickercontrollercameradevicerear,
Uiimagepickercontrollercameradevicefront
};
*/
BOOL isflushsupport = [Uiimagepickercontroller isflashavailableforcameradevice: Uiimagepickercontrollercameradevicerear];
NSLog (@ "Rear flash support:%d", isflushsupport);
Uiimagepickercontroller static method returns the shooting type supported by the front camera/rear camera
/*
typedef ns_enum (Nsinteger, Uiimagepickercontrollercameradevice) {
Uiimagepickercontrollercameradevicerear,
Uiimagepickercontrollercameradevicefront
};
*/
Return types have photos and videos
/*
enum {
Uiimagepickercontrollercameracapturemodephoto,
Uiimagepickercontrollercameracapturemodevideo
};
typedef Nsuinteger Uiimagepickercontrollercameracapturemode;
*/
nsarray* capturemodes = [Uiimagepickercontroller availablecapturemodesforcameradevice: Uiimagepickercontrollercameradevicerear];
For (nsnumber* mode in capturemodes) {
NSLog (@ "Capture modes:%d", [mode IntegerValue]);
}
Uiimagepickercontroller static method returns the media type supported by the camera/album/Photo gallery
/*
typedef ns_enum (Nsinteger, Uiimagepickercontrollersourcetype) {
Uiimagepickercontrollersourcetypephotolibrary,
Uiimagepickercontrollersourcetypecamera,
Uiimagepickercontrollersourcetypesavedphotosalbum
};
*/
Return type is kuttypemovie,kuttypeimage, other types are <MobileCoreServices/MobileCoreServices.h>
nsarray* mediatypes = [Uiimagepickercontroller availablemediatypesforsourcetype: Uiimagepickercontrollersourcetypecamera];
For (nsstring* type in mediatypes) {
NSLog (@ "Media types:%@", type);
}
2.UIImagePickerController attribute Details:
Specify to use camera mode, you can specify the use of album/Photo gallery
Imagepicker.sourcetype = Uiimagepickercontrollersourcetypecamera;
Sets whether to skip to edit mode for picture clipping when the photo is finished or after the album has been selected. Effective only if the Showscameracontrols property is True
imagepicker.allowsediting = YES;
Sets whether the toolbar below the photo is displayed, and if you need to customize the capture screen, you can hide the toolbar
Imagepicker.showscameracontrols = YES;
Set up the rear camera to use the front-facing camera
Imagepicker.cameradevice = Uiimagepickercontrollercameradevicerear;
Set Flash Mode
/*
typedef ns_enum (Nsinteger, Uiimagepickercontrollercameraflashmode) {
Uiimagepickercontrollercameraflashmodeoff =-1,
Uiimagepickercontrollercameraflashmodeauto = 0,
Uiimagepickercontrollercameraflashmodeon = 1
};
*/
Imagepicker.cameraflashmode = Uiimagepickercontrollercameraflashmodeauto;
Set the type of camera support, take photos and videos
Imagepicker.mediatypes = @[(nsstring*) kuttypeimage, (nsstring*) Kuttypemovie];
Set the Transform property of the view of the screen when shooting, can realize the rotation, zoom function
Imagepicker.cameraviewtransform = Cgaffinetransformmakerotation (m_pi*45/180);
Imagepicker.cameraviewtransform = Cgaffinetransformmakescale (1.5, 1.5);
All properties that contain cameraxxx must be sourcetype when set to Uiimagepickercontrollersourcetypecamera, otherwise there will be an exception
Set up a proxy for Uiimagepickercontroller
Imagepicker.delegate = self;
-(void) showcamera{
Presenting Imagepicker in modal mode
[Self presentmodalviewcontroller:imagepicker animated:yes];
}
Use Imagepicker.cameraviewtransform = Cgaffinetransformmakerotation (m_pi*45/180); Rotate 45 degree effect:
Use Imagepicker.cameraviewtransform = Cgaffinetransformmakescale (1.5, 1.5), full screen effect, and imagepicker.showscameracontrols = NO; hide the toolbar:
Use imagepicker.allowsediting = yes; the image editing effect appears only if imagepicker.showscameracontrols = yes;
Use Imagepicker.mediatypes = @[(nsstring*) kuttypeimage, (nsstring*) Kuttypemovie]; support for photo and video pre-and post-contrast effects:
3.UIImagePickerController Callback Explanation:
Success in getting a photo or a callback after a video
-(void) Imagepickercontroller: (Uiimagepickercontroller *) Picker Didfinishpickingmediawithinfo: (NSDictionary *) info {
To determine whether a photo or video is returned by Uiimagepickercontrollermediatype
nsstring* type = [Info objectforkey:uiimagepickercontrollermediatype];
If the returned type equals kuttypeimage, the representative returns the photo and needs to determine whether the sourcetype used by the current camera is a photo or photo album
if ([Type isequaltostring: (nsstring*) kuttypeimage]&&picker.sourcetype== Uiimagepickercontrollersourcetypecamera) {
Get the original picture of a photo
uiimage* original = [info objectforkey:uiimagepickercontrolleroriginalimage];
Get Picture cropped image
uiimage* edit = [info objectforkey:uiimagepickercontrollereditedimage];
After getting the picture cropped, the rest of the graph
uiimage* crop = [info objectforkey:uiimagepickercontrollercroprect];
Get the URL of a picture
nsurl* url = [info objectforkey:uiimagepickercontrollermediaurl];
Get metadata data information for a picture
nsdictionary* metadata = [info objectforkey:uiimagepickercontrollermediametadata];
If the photo is taken, you need to save it locally, and the photo will not be saved automatically after the successful photo
Uiimagewritetosavedphotosalbum (edit, Self, @selector (image:didFinishSavingWithError:contextInfo:), nil);
}else{
}
Modal Mode exit Uiimagepickercontroller
[Imagepicker Dismissmodalviewcontrolleranimated:yes];
}
Cancels the camera's callback
-(void) Imagepickercontrollerdidcancel: (Uiimagepickercontroller *) picker{
Modal Mode exit Uiimagepickercontroller
[Imagepicker Dismissmodalviewcontrolleranimated:yes];
}
Callback after saving the photo successfully
-(void) Image: (UIImage *) image didfinishsavingwitherror: (Nserror *) error
ContextInfo: (void *) contextinfo{
NSLog (@ "saved..");
}
4. Customize the camera Photo screen:
Sets whether the toolbar below the photo is displayed, and if you need to customize the capture screen, you can hide the toolbar
Imagepicker.showscameracontrols = NO;
uitoolbar* tool = [[Uitoolbar alloc]initwithframe:cgrectmake (0, self.view.frame.size.height-55 , Self.view.frame.size.width, 75)];
tool.barstyle = uibarstyleblacktranslucent;
uibarbuttonitem* Cancel = [[Uibarbuttonitem alloc]initwithbarbuttonsystemitem: Uibarbuttonsystemitemcancel target:self Action: @selector (Cancelcamera)];
uibarbuttonitem* add = [[Uibarbuttonitem alloc]initwithbarbuttonsystemitem: Uibarbuttonsystemitemsave target:self Action: @selector (Savephoto)];
[Tool Setitems:[nsarray Arraywithobjects:cancel,add, nil]];
//The custom view to the overlay property of Imagepickercontroller
Imagepicker.cameraoverlayview = tool;
-(void) cancelcamera{
[Imagepicker Dismissmodalviewcontrolleranimated:yes];
}
-(void) savephoto{
Take pictures, will automatically callback-(void) Imagepickercontroller: (Uiimagepickercontroller *) Picker Didfinishpickingmediawithinfo: ( Nsdictionary *) info, for a custom camera interface, the callback can be taken without exiting to achieve a continuous photo-taking effect
[Imagepicker Takepicture];
}
5.UIImagePickerController is an inherited Uinavigationcontroller, so you can push and pop some viewcontroller to navigate the effect. For example, when you customize the camera screen, you can push a viewcontroller after shooting to edit the photo.
Original link: http://blog.csdn.net/kingsley_cxz/article/details/9157093
Usage of IOS Uiimagepickercontroller