How reuse same CGContext?

138 views Asked by At

Many times each second, I modify an existing UIImage :

UIGraphicsBeginImageContextWithOptions(CGSize(width: 2000, height: 2000), false, 2)
let context = UIGraphicsGetCurrentContext()!
image.draw(at: CGPoint.zero)
... do stuff in context...
image = UIGraphicsGetImageFromCurrentImageContext()
UIGraphicsEndImageContext()

I create a new context each time and I need to call image.draw to load the content of the image before modifying it, but image.draw is very time consuming.

is there a way to use the same context along the user session ?

1

There are 1 answers

0
Shehata Gamal On

The drawing process isn't a something to be reused as it begins , draws , renders and finally ends , so every time you need to follow these 4 steps , meaning Context is not a heavy created object to be reused