[英]How to make a screenshot of OpenGl ES on top of the live preview camera in iOS (Augmented Reality app)?
[英]iOS screenshot live camera preview
我的應用程序(在scrollView中)具有實時攝像頭,要進行過渡,我需要拍攝攝像頭預覽的屏幕截圖並獲取該圖像,但是
drawHierarchy(in rect: CGRect,afterScreenUpdates afterUpdates: Bool)
方法沒有幫助。 有沒有辦法在沒有OpenGL的情況下實現這一目標。 請幫忙,因為我已經在搜索解決方案了幾天。
UIGraphicsBeginImageContextWithOptions((self.getRectOfSceneInScrollView(index: self.selectedSceneIndex!).size), false, 0);
self.scrollView.drawHierarchy(in: CGRect.init(--some rect--), afterScreenUpdates: true)
let image:UIImage = UIGraphicsGetImageFromCurrentImageContext()!;
UIGraphicsEndImageContext()
更新:self.scrollView.layer.render(在:UIGraphicsGetCurrentContext()!)也無濟於事
蘋果在使用UIGraphicsGetImageFromCurrentImageContext
從我們的自定義攝像機視圖捕獲AVCaptureVideoPreviewLayer
方面存在一些限制。 如果我們有攝像機視圖,則即使UIView
Snapchat方法也無法使用。
但是我們確實有一種變通辦法來獲得效果。 獲取每個相機幀的圖像緩沖區,並將其轉換為UIImage
。 手動將圖像添加到我們的屏幕截圖中。 並不是那么簡單,並且AFAIK這是最好的解決方法。 可以在SO解答中找到更多信息。可以在圖形上下文中渲染AVCaptureVideoPreviewLayer嗎?
func takeScreenshot(view: UIView) -> UIImageView {
UIGraphicsBeginImageContext(view.frame.size)
view.layer.renderInContext(UIGraphicsGetCurrentContext())
let image = UIGraphicsGetImageFromCurrentImageContext()
UIGraphicsEndImageContext()
UIImageWriteToSavedPhotosAlbum(image, nil, nil, nil)
return UIImageView(image: image)
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.