0
我用AVCaptureVideoPreviewLayer来显示实时视频流,这样的事情:显示实况视频流,但无法通过UIGraphicsGetCurrentContext捕捉图像?
AVCaptureSession *captureSession = yourcapturesession;
previewLayer = [AVCaptureVideoPreviewLayer layerWithSession:captureSession];
UIView *aView = theViewYouWantTheLayerIn;
previewLayer.frame = aView.bounds;
[aView.layer addSublayer:previewLayer];
然后我用这个来捕捉图像。我得到一个UIImage对象,但图像是黑色的:
UIGraphicsBeginImageContext(self.previewLayer.bounds.size);
[self.previewLayer renderInContext:UIGraphicsGetCurrentContext()];
UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
NSLog("%@",image);
这里有什么问题?
请试试这个:http://stackoverflow.com/questions/3397899/avcapturevideopreviewlayer-taking-a-snapshot。希望有所帮助! –