The iPhone has a built-in camera and nifty application called photos to help you to manage all those awesome pictures you’ve taken . Your programs can use the built-in camera to take pictures and your your program can also allow the user to select picture from among the photos already on the iPhone. The both camera and image library are made available to your application by way of an image picker.
Step 1: Create a new project in Xcode using the view base application and naming the application.
Step 2:Xcode automatically creates the directory structure and adds essential frameworks to it. You can explore the directory structure to check out the content of the directory.
Step 3: Single click ViewController.h file and add UIButton, UIImage ,IBAction also. Make the following changes into the file.
@interface CameraViewController : UIViewController
< UIImagePickerControllerDelegate , UINavigationControllerDelegate>
IBOutlet UIImageView *imageView;
IBOutlet UIButton *takePictureButton;
IBOutlet UIButton *selectFromCameraRollButton;
@property(nonatomic,retain) UIImageView *imageView;
@property(nonatomic,retain) UIButton *takePictureButton;
@property(nonatomic,retain) UIButton *selectFromCameraRollButton;
Step 4: Double click .xib file, open it to the Interface Builder. Drag two Round Rect button from the library and place it bottom of the view window. Give it a title of Camera and Library. Next drag image view from the library, and place it above the buttons. Now connect the File’s Owner icon to the image view and select imageView. Single click camera button and bring up connection inspector . Drag Touch Up Inside event to File’s Owner, and select the getCameraPicture: action. Next select Library button and bring up connection inspector . Drag Touch Up Inside event to File’s Owner, and select the selectExitingPicture: action. Now Save your .xib file and go back to the Xcode.
Step 5: Single click your ViewController.m file . Add two methods and two delegate methods. Make the following changes.
UIImagePickerController *picker = [[UIImagePickerController alloc] init];
picker.delegate = self;
picker.allowsImageEditing = YES;
picker.sourceType = (sender == takePictureButton) ? UIImagePickerControllerSourceTypeCamera :
[self presentModalViewController: picker animated:YES];
UIImagePickerController *picker= [[UIImagePickerController alloc]init];
picker.delegate = self;
picker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
[self presentModalViewController:picker animated:YES];
didFinishPickingImage : (UIImage *)image
imageView.image = image;
-(void)imagePickerControllerDidCancel:(UIImagePickerController *) picker
Step 6: Now compile your application run into the simulator. But you do not have the option to take a new photo. If you have the opportunity to run the on a real device, go ahead and try it.
Figure 1: This is the Library view.
You can downloaded SourceCode from here Camera
25 Useful HTML5 and CSS3 Tools for Designers and Developers
The Languages and Frameworks You Should Learn in 2017
Awesome Programming Tools and Resources
30 Java Programming Tips and Best Practices
Best 15 Unix Command Line Tools
50 Useful and Reasonably Popular Linux Applications
38 Linux Commands and Utilities You CANT Live without
Strings and Characters in Swift