uiimagepickercontroller1.+ (BOOL) issourcetypeavailable: (Uiimagepickercontrollersourcetype) SourceType; Checks whether the specified source is available on the device.
Check if photo feeds are available
[Uiimagepickercontroller Issourcetypeavailable:uiimagepickercontrollersourcetypephotolibrary] 2.allowsEditing Default No
Whether to allow editing
Allow editing.
[Imagepicker Setallowsediting:yes];
3. Videomaximumduration
Sets the maximum video duration for the uiimagepicker. Default 10 minutes
4. + Availablemediatypesforsourcetype://Specify the type of media available for the source
Get media types supported in camera mode
nsarray* availablemediatypes = [Uiimagepickercontroller availablemediatypesforsourcetype: Uiimagepickercontrollersourcetypecamera];
5. SourceType
Set the Uiimagepicker photo source type, which has 3 default types.
Photo Source Type
Uiimagepickercontrollersourcetypecamera camera
Uiimagepickercontrollersourcetypephotolibrary photo gallery (stored by sync, user cannot delete)
Uiimagepickercontrollersourcetypesavedphotosalbum saved photos (saved by photo or screenshot, user can delete)
6.UIImagePicker Use steps:
Checks whether the specified source is available. Issourcetypeavailable: Method.
Check whether the available media (video or only pictures) Availablemediatypesforsourcetype: method.
Set interface Media Properties MediaTypes property.
The display interface uses the PresentViewController:animated:completion: method. The ipad is in popover form. You need to make sure that the sourcetype is valid.
Related actions to remove the view.
If you want to create an image picker with a fully customizable interface to browse the pictures, use the classes in the Assets Library Framework reference. ("Media Capture and Access to Camera" in AV Foundation Programming Guide)
7. Set the source
+ Availablemediatypesforsourcetype://Specify the type of media available for the source
+ issourcetypeavailable://Specify whether the source is available on the device
SourceType
The source type needs to be indicated before running the related interface. Must be valid, or throw an exception. Picker has been shown to change this value, picker will change accordingly to adapt. Default uiimagepickercontrollersourcetypephotolibrary.
8. Setting the Picker property
Allowsediting//Is editable
Delegate
MediaTypes
Indicates the type of media that is displayed in picker. Apply Availablemediatypesforsourcetype before setting each type: Check it. An exception occurs if NULL or if the type in array is not available. Default Kuttypeimage, Only pictures can be displayed.
9.video Selecting parameters
Videoquality///video capture when selecting the encoding quality. Valid only if MediaTypes contains Kuttypemovie.
Videomaximumduration//sec, video Maximum recording time, default 10 minutes. Valid only when MediaTypes contains Kuttypemovie.
10. Custom interface
Showscameracontrols
Indicates whether picker displays the default camera controls. The default is yes, set to No to hide the default controls to use a custom overlay view. (so you can implement multiple selections instead of choosing one picker dismiss). Only Uiimagepickercontrollersourcetypecamera source is valid, otherwise nsinvalidargumentexception exception.
Cameraoverlayview
Custom view that is used to display above picker. Valid only when the source is Uiimagepickercontrollersourcetypecamera. Other times use the throw nsinvalidargumentexception exception.
Cameraviewtransform
Pre-animated. Affects only pre-images and is not valid for custom overlay view and default picker. Used only when the source of picker is Uiimagepickercontrollersourcetypecamera, Otherwise nsinvalidargumentexception exception.
11. Select Media
–takepicture
Use the camera to select a picture. Custom overlay can be multi-selected. There is already a picture being selected that is invalid for the call and must wait for delegate to receive Imagepickercontroller:didfinishpickingmediawithinfo: Message before it can be picked again. Non-Uiimagepickercontrollersourcetypecamera sources can cause exceptions.
–startvideocapture
–stopvideocapture
End the video selection, and then the system calls delegate's Imagepickercontroller:didfinishpickingmediawithinfo: method.
12. Setting up the camera
Cameradevice//Lens Used (default rear)
+ iscameradeviceavailable://Camera device is available.
+ Availablecapturemodesforcameradevice://Selection mode available for the device
Cameracapturemode//Camera Capture mode
Cameraflashmode//Flash mode (default auto)
+ Isflashavailableforcameradevice://whether there is flash capability
13.UIImagePickerControllerDelegate
Use Uiimagewritetosavedphotosalbum to save the image, Uisavevideoatpathtosavedphotosalbum save the video. Use WriteImageToSavedPhotosAlbum:metadata:completionBlock after 4.0: Save metadata.
-(void) Imagepickercontroller: (Uiimagepickercontroller *) Picker Didfinishpickingmediawithinfo: (NSDictionary *) info
Include the selected picture or a video URL, as described in "Editing information Keys."
If you set an editable property, picker will pre-display the selected media, and the edited and original will be saved in info.
–imagepickercontrollerdidcancel:
–imagepickercontroller:didfinishpickingimage:editinginfo://deprecated in IOS 3.0
NSString *const uiimagepickercontrollermediatype;//Media type
NSString *const uiimagepickercontrolleroriginalimage;//Original unedited image
NSString *const uiimagepickercontrollereditedimage;//edited image
NSString *const uiimagepickercontrollercroprect;//Source image editable (valid?) Regional
NSString *const uiimagepickercontrollermediaurl;//Video Path
NSString *const uiimagepickercontrollerreferenceurl;//The URL of the original selection
NSString *const uiimagepickercontrollermediametadata;//is valid only when using the camera and is an image type. The type of dictionary that contains the selection image information
Uiimagepickercontroller Small Example
Uiimagepickercontroller agents are required to abide by these two protocols. <uiimagepickercontrollerdelegate, Uinavigationcontrollerdelegate>
#pragma mark Select a photo
-(void) Selectphoto
{
1. First determine if the photo source is available
if ([Uiimagepickercontroller issourcetypeavailable:uiimagepickercontrollersourcetypephotolibrary]) {
0) Instantiating the controller
Uiimagepickercontroller *picker = [[Uiimagepickercontroller alloc]init];
1) Set Photo source
[Picker setsourcetype:uiimagepickercontrollersourcetypephotolibrary];
2) settings Allow modification
[Picker Setallowsediting:yes];
3) Set up the agent
[Picker setdelegate:self];
4) Display Controller
[Self Presentviewcontroller:picker animated:yes completion:nil];
} else {
NSLog (@ "photo source not available");
}
}
#pragma Mark-imagepicker Proxy method
-(void) Imagepickercontroller: (Uiimagepickercontroller *) Picker Didfinishpickingmediawithinfo: (NSDictionary *) info
{
UIImage *image = info[@ "Uiimagepickercontrollereditedimage"];
[_imagebutton setimage:image Forstate:uicontrolstatenormal];
Turn off photo Selector
[Self dismissviewcontrolleranimated:yes completion:nil];
Need to save photos to the application sandbox, as it relates to data storage, and is not interface-Independent
You can save images using multiple threads
Dispatch_async (Dispatch_get_global_queue (dispatch_queue_priority_default, 0), ^{
Save Image
1. Take image Path
Nsarray *docs = Nssearchpathfordirectoriesindomains (NSDocumentDirectory, Nsuserdomainmask, YES);
NSString *imagepath = [docs[0]stringbyappendingpathcomponent:@ "Abc.png"];
2. Convert to NSData Save
NSData *imagedata = uiimagepngrepresentation (image);
[ImageData Writetofile:imagepath Atomically:yes];
});
}
Uiimagepicker Photo Selector