iosuiimagecalayerscreen-capturecamera-overlay

Camera controller not working when taking screenshot


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);

Solution

  • 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.