0

I took screenshot of overlay image with background camera controller. But background cameracontroller layer is hiding when taking picture

code:

CGRect rect = [previewView bounds];
UIGraphicsBeginImageContext(rect.size);
CGContextRef context = UIGraphicsGetCurrentContext();
[previewView.layer renderInContext:context];   
UIImage *img = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
 UIImageWriteToSavedPhotosAlbum(img, nil, nil, nil);
Ram
  • 1,687
  • 3
  • 18
  • 28

1 Answers1

1

The camera preview layer is not a common CALayer and is not taken into account with render in context. Render in context works only with a kind of CALayer. The most effettive way is get a screenshot directly from the camera buffer.

Andrea
  • 26,120
  • 10
  • 85
  • 131
  • Is there any way to take UIImage with cameralayer. I searched so many tutorials. help me.. – Ram Mar 27 '13 at 05:24
  • Unfortunatly no as I know in an easy way. One time ago it was accepted to use a special function UIGetScreenImage() but is a private API, if you are building for AppStore most likely you will get a reject. I suggest you to read this SO answers http://stackoverflow.com/questions/2200736/how-to-take-a-screenshot-programmatically and this tech note from Apple you will find it very helpful http://developer.apple.com/library/ios/ipad/#qa/qa1714/_index.html – Andrea Mar 27 '13 at 05:45