Uiimagepickercontroller image selector-call cameras and photo Repositories on iPhone-iOS development

Source: Internet
Author: User
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

Related Article

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.