1

I need to make a screenshot of ARSCNView, the class is defined as below:

public class SceneLocationView: ARSCNView, ARSCNViewDelegate { }

I am following the below methods to have the screenshot done: How do I take a full screen Screenshot in Swift?

but the scenelocationview view is not printed, all the rest is.

Anyone was able to do this successfully ?

Vadim Kotov
  • 8,084
  • 8
  • 48
  • 62
czane
  • 392
  • 1
  • 6
  • 18

2 Answers2

6

There is also another way:

ARSCNView has a built in function: .snapshot()

This can be called easily like so:

  let renderedImage = augmentedRealityView.snapshot()

And it may also be more useful as I believe that it doesn't render any UIKit elements such as UINavigationBar as well.

BlackMirrorz
  • 7,217
  • 2
  • 20
  • 31
3

Try this extension,

extension UIView {
    var snapshot: UIImage? {
        UIGraphicsBeginImageContextWithOptions(bounds.size, false, 0)
        defer { UIGraphicsEndImageContext() }
        drawHierarchy(in: bounds, afterScreenUpdates: true)
        return UIGraphicsGetImageFromCurrentImageContext()
    }
}

and use

let screenShot = self.view?.snapshot

I was able to save the screenshot of OpenGL View from this extension.

Asis
  • 683
  • 3
  • 23
  • That worked like a charm! Thanks a lot for that. Do you have any idea how to hide toolbar with your extension? Thanks again. – czane Mar 01 '18 at 13:36
  • you want to hide toolbar before taking screen shot ? – Asis Mar 01 '18 at 13:46
  • I want to take the screenshot without having the toolbar. If the only way to do so is to hide it i will do and then wet it visible again, but please let me know if that is the only way you know to achieve it. Thanks. – czane Mar 01 '18 at 14:00