Statement You are welcome to repost this article, but please respect the author's Labor achievements. repost this article and keep the statement in this box. Thank you. ArticleSource: http://blog.csdn.net/iukey |
Uiimagepickercontroller the image selector is a navigation controller class that allows youProgramAdd a simple image selection function or camera interface. The user will see an image selection screen where a photo is selected. The source of the photo is his own photo library, saved album or camera. After you select a photo, the delegate of the selector is notified through the method in the uiimagepickerdelegate protocol.
You can use the uiimagepickercontroller class to create an image selector and add it to a window as an independent navigation controller.
1. Create and add it to the view
Uiimagepickercontroller * picker = [[uiimagepickercontroller alloc] init]; [self. View addsubview: picker. View];
Ii. Image Source
You can use the sourcetype attribute to set multiple image sources and present them to users:
Picker. sourcetype = uiimagepickercontrollersourcetypesavedphotosalbum;
You can use the following sources:
Enum {uiimagepickercontrollersourcetypephotolibrary, // photo library uiimagepickercontrollersourcetypecamera, // camera photo // saved photo}; typedef nsuinteger uiimagepickercontrollersourcetype;
Iii. image editing
You can set the allowsimageediting attribute to yes to enable the image editing function:
Picker. allowsediting = yes;
Iv. Image Selection
After you select an image, the selector delegate will receive a notification through the didfinishpickingimage method. The proxy will get a uiimage object containing the image. If the editing function is enabled, it will also get an nsdictionary containing the editing attribute.
Set the delegate of the selector to assign a delegate to the selector:
Picker. Delegate = self;
The following method is implemented in your delegate class, so that when you select an image, the delegate class will be notified:
-(Void) imagepickercontroller :( uiimagepickercontroller *) picker didfinishpickingimage :( uiimage *) image editinginfo :( nsdictionary *) editinginfo {/* Add and process the selected ImageCode*/}
The parameters of the method include a pointer pointing to the image selector controller reporting the current operation, so that you can process multiple selector in one delegate. The parameter also includes a pointer to the uiimage object and a dictionary object, which contains information about how the image is scaled and moved on the screen.
You may also want to be notified when you cancel image selection. To achieve this goal, you must implement the imagepickercontrollerdidcancel method in the proxy. It will be called when the selection is canceled, with the pointer to the canceled image selector as the parameter:
-(Void) imagepickercontrollerdidcancel :( uiimagepickercontroller *) picker {/* Add code to process and cancel the selected image */}
The code example is attached. Uiimagepickercontrollerdemo