iOS camera management
IOS Camera Management
Camera Introduction
Camera is one of the common features of mobile devices. We can use the camera to take pictures and call it in the application , and the camera is easy to use.
Instance steps
1. Create a simple View based application
2. Add a button (button) to ViewController.xib and create an IBAction for the button
3. Add an image view (image view) and create an IBOutlet named imageView
4. The ViewController.h file code is as follows:
#import <UIKit/UIKit.h>@interface ViewController : UIViewController<UIImagePickerControllerDelegate>{ UIImagePickerController *imagePicker; IBOutlet UIImageView *imageView; }- (IBAction)showCamera:(id)sender;@end
5. Modify ViewController.m as follows:
#import "ViewController.h"@interface ViewController ()@end@implementation ViewController- (void)viewDidLoad{ [super viewDidLoad]; }- (void)didReceiveMemoryWarning{ [super didReceiveMemoryWarning]; // Dispose of any resources that can be recreated.}- (IBAction)showCamera:(id)sender { imagePicker.allowsEditing = YES; if ([UIImagePickerController isSourceTypeAvailable: UIImagePickerControllerSourceTypeCamera]) { imagePicker.sourceType = UIImagePickerControllerSourceTypeCamera; } else{ imagePicker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary; } [self presentModalViewController:imagePicker animated:YES];}-(void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info{ UIImage *image = [info objectForKey:UIImagePickerControllerEditedImage]; if (image == nil) { image = [info objectForKey:UIImagePickerControllerOriginalImage]; } imageView.image = image; }-(void)imagePickerControllerDidCancel:(UIImagePickerController *)picker{ [self dismissModalViewControllerAnimated:YES];}@end
Output
When we run the application and click the Show Camera button, we will get the following output
After taking a photo, you can edit the picture by moving and zooming, as shown below.