iOS屏幕快照实时摄像头预览 [英] iOS screenshot live camera preview

查看:471
本文介绍了iOS屏幕快照实时摄像头预览的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的应用程序中有实时摄像头(在scrollView中),要进行过渡,我需要获取摄像头预览的屏幕截图并获取该图像,但是

  drawHierarchy(在rect:CGRect,afterScreenUpdates afterUpdates:Bool)

方法不帮帮我。有没有办法在没有OpenGL的情况下实现这一目标。请帮忙,因为已经有好几天我正在寻找解决方案。 !)。size),false,0);
self.scrollView.drawHierarchy(in:CGRect.init(-some rect--),afterScreenUpdates:true)

let image:UIImage = UIImageicsGetImageFromCurrentImageContext()!;

UIGraphicsEndImageContext()

更新:
self.scrollView。 layer.render(在UIGraphicsGetCurrentContext()中!)也无济于事

解决方案

Apple在捕获<$时有一些限制通过使用 UIGraphicsGetImageFromCurrentImageContext 从我们的自定义摄像机视图中获取c $ c> AVCaptureVideoPreviewLayer 。如果我们有相机视图,即使 UIView Snapchat方法也无法使用。



但是我们确实有一种变通方法来获得效果。获取每个相机帧的图像缓冲区,并将其转换为 UIImage 。手动将图像添加到我们的屏幕截图中。并不是那么简单,并且AFAIK这是最好的解决方法。可以从 SO答案中找到更多信息在图形环境中渲染AVCaptureVideoPreviewLayer?


I have live camera in my app (in scrollView) and for transition I need to take screenshot of camera preview and get that image, but

 drawHierarchy(in rect: CGRect,afterScreenUpdates afterUpdates: Bool) 

method doesn't help. Is there a way to achieve this without OpenGL. Please help, cause it's already several days I am searching the solution.

 UIGraphicsBeginImageContextWithOptions((self.getRectOfSceneInScrollView(index: self.selectedSceneIndex!).size), false, 0);
self.scrollView.drawHierarchy(in: CGRect.init(--some rect--), afterScreenUpdates: true)

let image:UIImage = UIGraphicsGetImageFromCurrentImageContext()!;

UIGraphicsEndImageContext()

UPDATE: self.scrollView.layer.render(in: UIGraphicsGetCurrentContext()!) doesn't help too

解决方案

Apple has some restrictions on capturing the AVCaptureVideoPreviewLayer from our custom camera view by using UIGraphicsGetImageFromCurrentImageContext. Even UIView Snapchat method will not work if we have camera view.

But we do have a workaround to get the effect. Get the image buffer for each camera frame and convert it to UIImage. Add the image to our screenshot manually. It's not that simple and AFAIK this is the best workaround. More info can be found in SO Answer from Is it possible to render AVCaptureVideoPreviewLayer in a graphics context?

这篇关于iOS屏幕快照实时摄像头预览的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆