iOS Tutorial
iOS Useful Resources
Selected Reading
- iOS - Application Debugging
- iOS - Memory Management
- iOS - Twitter & Facebook
- iOS - Auto Layouts
- iOS - Storyboards
- iOS - GameKit
- iOS - iAd Integration
- iOS - In-App Purchase
- iOS - Accessing Maps
- iOS - File Handling
- iOS - Audio & Video
- iOS - Sending Email
- iOS - SQLite Database
- iOS - Location Handling
- iOS - Camera Management
- iOS - Universal Applications
- iOS - Accelerometer
- iOS - UI Elements
- iOS - Delegates
- iOS - Actions and Outlets
- iOS - First iPhone Application
- iOS - Objective-C Basics
- iOS - Environment Setup
- iOS - Getting Started
- iOS - Home
iOS Useful Resources
Selected Reading
- Who is Who
- Computer Glossary
- HR Interview Questions
- Effective Resume Writing
- Questions and Answers
- UPSC IAS Exams Notes
iOS - Camera Management
iOS - Camera Management
Camera is one of the common features in a mobile device. It is possible for us to take pictures with the camera and use it in our apppcation and it is quite simple too.
Camera Management – Steps Involved
Step 1 − Create a simple View based apppcation.
Step 2 − Add a button in ViewController.xib and create IBAction for the button.
Step 3 − Add an image view and create IBOutlet naming it as imageView.
Step 4 − Update ViewController.h as follows −
#import <UIKit/UIKit.h> @interface ViewController : UIViewController<UIImagePickerControllerDelegate> { UIImagePickerController *imagePicker; IBOutlet UIImageView *imageView; } - (IBAction)showCamera:(id)sender; @end
Step 5 − Update 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 apppcation and cpck show camera button, we ll get the following output −
Once we take a picture, we can edit the picture, i.e., move and scale as shown below −
Advertisements