问题描述
我的应用程序中有实时摄像头(在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这是最好的解决方法。可以从
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屏幕快照实时摄像头预览的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!