IOS hardware development camera-image selector usage

Source: Internet
Author: User

1. Create an empty application and add a view. The XIB design is as follows:

 

2. when using uiimagepickercontroller, you must specify several very important attributes: Specify the source type (determine whether the source is available before specifying), specify the delegate, and specify whether the image can be edited. After setting, you can start it and "push" it out.

 

 

-(Ibaction) takenewphoto :( ID) sender

{
// Create an image Selector
Uiimagepickercontroller * imagepicker = [[uiimagepickercontroller alloc] init];

// Check whether the image source is available before specifying the source type
If ([uiimagepickercontroller issourcetypeavailable: uiimagepickercontrollersourcetypecamera])
{
// Specify the source type
Imagepicker. sourcetype = uiimagepickercontrollersourcetypecamera;

// Before selecting an image, you can simply edit the image to be selected. This includes changing the image selection range by moving up or down, and changing the image size by hand.
Imagepicker. allowsediting = yes;

// Implement the delegate. The delegate must implement the uiimagepickercontrollerdelegate protocol for the user's actions in the image selector.
Imagepicker. Delegate = self;

// After iamgepicker is set, it can be started. Use the following method to "push" the view of the image Selector
[Self presentmodalviewcontroller: imagepicker animated: Yes];

[Imagepicker release];
}
Else
{
Uialertview * Alert = [[uialertview alloc] initwithtitle: Nil message: @ "the camera cannot use" delegate: Nil cancelbuttontitle: @ "Disable" otherbuttontitles: Nil];
[Alert show];
[Alert release];
}
}

 

 

3. Use the uiimagepickercontrollerdelegate protocol to perform operations on users.

 

# Pragma mark-
# Pragma mark uiimagepickercontrollerdelegate protocol Method

// The image is called when you click the "cancel" button in the image selector. This indicates that you want to abort the image selection operation.
-(Void) imagepickercontrollerdidcancel :( uiimagepickercontroller *) picker
{
[Picker dismissmodalviewcontrolleranimated: Yes];
}

// The user is called when he clicks the "choose" button in the selector to notify the delegate object that the selection operation has been completed and the instance of the selected image is returned.
-(Void) imagepickercontroller :( uiimagepickercontroller *) picker didfinishpickingimage :( uiimage *) image editinginfo :( nsdictionary *) editinginfo
{
Noticelabel. Hidden = yes;
[Imageview setimage: Image];
[Picker dismissmodalviewcontrolleranimated: Yes];

}

 

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.