-2

Possible Duplicate:
Access the camera with iPhone SDK

How do I take a photograph in an iPhone app?

Which API can I use?

Please provide sample code.

Community
  • 1
  • 1
jaleel
  • 1,169
  • 8
  • 22
  • 46
  • Please search before posting new questions. This question is a duplicate of:http://stackoverflow.com/questions/74113/access-the-camera-with-iphone-sdk – Moshe Nov 12 '10 at 04:00
  • screenshot of application or camera photo? – raidfive Nov 12 '10 at 06:01
  • Duplicate of: [Access The Camera with iPhone SDK](http://stackoverflow.com/questions/74113/access-the-camera-with-iphone-sdk) – Mario Nov 12 '10 at 03:45

1 Answers1

2
UIGraphicsBeginImageContext(self.view.bounds.size);

[self.view.layer renderInContext:UIGraphicsGetCurrentContext()];
UIImage *saveImage = UIGraphicsGetImageFromCurrentImageContext();   
CGContextRef context = UIGraphicsGetCurrentContext();

UIImageWriteToSavedPhotosAlbum(saveImage, self, @selector(image:didFinishSavingWithError:contextInfo:), &context);
UIGraphicsEndImageContext();

// saving image in documents folder
NSData *imageData = UIImagePNGRepresentation(saveImage);
NSString *imageName = @"temp.png";

NSArray* paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString* documentsDirectory = [paths objectAtIndex:0];

NSString* fullPathToFile = [documentsDirectory stringByAppendingPathComponent:imageName];
[imageData writeToFile:fullPathToFile atomically:NO];
Wevah
  • 28,182
  • 7
  • 83
  • 72
Swastik
  • 2,415
  • 2
  • 31
  • 61