In this application we will see how to image capture in iPhone without using camera. So let see how it will worked.
Step 1: Open the Xcode, Create a new project using View Base application. Give the application “ImageClick”.
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 ViewController class for you. Expand Resources and notice the template generated a separate nib, ImageClickViewController.xib for the ImageClick application.
Step 4: We need to add one image in the resource in the application. Give the name
Step 5: Open the ImageClickViewController.h file and make the following changes:
@interface ImageClickViewController : UIViewController {
UIImageView *image;
}
@property (nonatomic, retain) IBOutlet UIImageView *image;
–(IBAction)PhotoCapture:(id)sender;
@end
Step 6: Double click the ImageClickViewController.xib file and open it to the interface Builder. Drag the image view and round rect button from the library and place it to the View window. Now select the button and bring up Connection
Inspector and connect Touch Up Inside to the File’s Owner icon and select PhotoCapture: method and select the imageview and bring up Attribute Inspector and select the background image.Now Save the .xib file, close it and go back to the Xcode.
Step 7: Open the ImageClickViewController.m file and make the following changes:
@implementation ImageClickViewController
@synthesize image;
– (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.
}
–(IBAction)PhotoCapture:(id)sender
{
UIGraphicsBeginImageContext(image.frame.size);
[self.view.layer renderInContext:UIGraphicsGetCurrentContext()];
UIImage *viewImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
UIImageWriteToSavedPhotosAlbum(viewImage, nil, nil, nil);
}
#pragma mark – View lifecycle
/*
// Implement viewDidLoad to do additional setup after loading the view, typically from a nib.
– (void)viewDidLoad
{
[super viewDidLoad];
}
*/
– (void)viewDidUnload
{
[super viewDidUnload];
// Release any retained subviews of the main view.
// e.g. self.myOutlet = nil;
}
– (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
// Return YES for supported orientations
return (interfaceOrientation == UIInterfaceOrientationPortrait);
}
@end
Step 8: Now Compile and run the application on the Simulator. Click the “Capture Snap” button, it will automatically capture the background image and save it in the photos.

