显示实时视频流,但无法通过 UIGraphicsGetCurrentContext 捕获图像?
我使用 AVCaptureVideoPreviewLayer 来显示实时视频流,如下所示:
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);
这里有什么问题?
I use AVCaptureVideoPreviewLayer to display the live video streaming, something like this:
AVCaptureSession *captureSession = yourcapturesession;
previewLayer = [AVCaptureVideoPreviewLayer layerWithSession:captureSession];
UIView *aView = theViewYouWantTheLayerIn;
previewLayer.frame = aView.bounds;
[aView.layer addSublayer:previewLayer];
then I use this to capture the image. I get a UIImage object but the image is black:
UIGraphicsBeginImageContext(self.previewLayer.bounds.size);
[self.previewLayer renderInContext:UIGraphicsGetCurrentContext()];
UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
NSLog("%@",image);
What is the problem here?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
也尝试这样做,结果相同 - 没有图像。
我认为答案是这是不可行的,因为它并没有真正将 RGB 图像移交给上下文,只是“通过视口显示它”或类似的东西,如果这有意义的话。
Tried doing this too, w/ the same results - no image.
I think the answer is that it's just not doable because it's not really handing over the RGB image to the context, just "showing it through a viewport" or something similar, if that makes sense.