0

I have a context that needs to be around for the life of my app because it is a buffer that I continuously render images into. It is created using CGBitmapContextCreate on my main thread when the app launches.

Is it safe to later call the following code from a background thread in an NSOperation?

CGImageRef imageRef = [[UIImage imageWithContentsOfFile:[fileURL path]] CGImage];
if (imageRef)
{
    //  Draw the base image to the bitmap context
    CGContextDrawImage(myContext, myRect, imageRef);
}
Trygve
  • 1,317
  • 10
  • 27
  • Does this answer your question? [Can I draw to the same CGContextRef from multiple threads?](https://stackoverflow.com/questions/27064119/can-i-draw-to-the-same-cgcontextref-from-multiple-threads) – Gereon Dec 29 '19 at 10:19
  • Nope, it doesn't. I currently do draw into a context from multiple threads, but I do it at the pixel level after using `CGBitmapContextGetData` to get the base address of the pixels. In the case of `CGContextDrawImage` I have a large image that takes about 1 second to draw into the image and I'd like to put it on a background thread. At the time it would run, no other thread would be drawing to it, but it would be drawing on a different thread than the thread that created the context originally. – Trygve Dec 29 '19 at 18:07

0 Answers0