2

I'm trying to render a UIView (with subviews) into a UIImage.

I'm using the new iOS 10+ UIGraphicsImageRenderer as seen below

let renderer = UIGraphicsImageRenderer(size: view.bounds.size)
let image = renderer.image { ctx in
    view.drawHierarchy(in: view.bounds, afterScreenUpdates: true)
}

But my question is how can I do this faster? I'm trying to render this UIImage before I push a new UIViewController and it has a super long delay until the UIImage is finished processing. I think this is because the renderer UIGraphicsImageRendererContext is being created for every instantiation.

Is there any way to preload the context in the background before it needs to be used to render the image?

Or am I thinking about optimizing this wrong?

Any help would be appreciated.

siefix
  • 916
  • 1
  • 10
  • 19
  • Do you call the code you added in `viewDidLoad`? – Roman Podymov Jul 31 '19 at 09:38
  • No I do this before pushing to a new viewcontroller. I'm rendering a UIView that has filters and other effects applied to it so I have to wait until the user is finished before I can run this code – siefix Jul 31 '19 at 15:53

0 Answers0