2011-08-15 56 views
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); 

这里有什么问题?

+0

请试试这个:http://stackoverflow.com/questions/3397899/avcapturevideopreviewlayer-taking-a-snapshot。希望有所帮助! –

回答

1

也试过这样做,w /相同的结果 - 没有图像。

我认为答案是它是不可行的,因为它不是真正将RGB图像交给上下文,只是“通过视口显示”或类似的东西,如果这是有道理的。