PhotoCapture Application in iPhone

In this application we will see how to capture photo of the view in the application by using button pressed and save the photo in the Photo gallery. So let see how it will worked.

Step 1: Open the Xcode, Create a new project using View Base application. Give the application “PhotoCapture”.

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: Expand classes and notice Interface Builder created the RootViewController class for you. Expand Resources and
notice the template generated a separate nib, PhotoCaptureViewController.xib for the PhotoCaptureViewController class.

Step 4: Open the PhotoCaptureViewController.h file and make the following changes:

#import <UIKit/UIKit.h>
@interface PhotoCaptureViewController : UIViewController {
}
(IBAction)captureScreen:(id)sender;
@end

Step 5: Double click the PhotoCaptureViewController.xib file and open it to the Interface Builder. First drag the label from the library andplace it to the view window. Select the label from the view and bring up Attribute Inspector and change the Text into “Welcome To iPhone” . Now save the .xib file, close it and go back to the Xcode.

Step 6: In the PhotoCaptureViewController.m file make the following changes:

#import "PhotoCaptureViewController.h"
@implementation PhotoCaptureViewController
(IBAction)captureScreen:(id)sender
{
UIGraphicsBeginImageContext(self.view.frame.size);
[self.view.layer renderInContext:UIGraphicsGetCurrentContext()];
UIImage *viewImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
UIImageWriteToSavedPhotosAlbum(viewImage, nil, nil, nil);
}
(void)dealloc
{
[super dealloc];
}
(void)didReceiveMemoryWarning
{
// Releases the view if it doesn’t have a superview.
[super didReceiveMemoryWarning];
// Release any cached data, images, etc that aren’t in use.
}
(void)viewDidUnload
{
[super viewDidUnload];
}
(BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
// Return YES for supported orientations
return (interfaceOrientation == UIInterfaceOrientationPortrait);
}
@end

Step 7: Now compile and run the application in the Simulator and check Save image in the Photo Gallery.

You can Download SourceCode from here PhotoCapture.

Leave a Reply

Your email address will not be published. Required fields are marked *