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。希望有所幫助! –