I want to move some code that takes a couple seconds to generate a UIImage on another thread, but im getting a context error when using
UIGraphicsBeginImageContextWithOptions(size,false,0);
before calling the dispatch to generate the image saying “invalid context 0x0” for each operation i try to do. Is this at all possible?
What’s New in iOS: iOS 4.0 says this:
It sounds like you tried something like this:
That won’t work because each thread has its own stack of graphics contexts (starting in iOS 4.0). You need to do it like this:
UPDATE
The documentation for
UIGraphicsBeginImageContextWithOptionsand other UIKit graphics functions now saysThe documentation for
UIColorsaysThe documentation for
UIFontsaysHowever, the documentation for the UIKit
NSString-drawing additions saysSo you must not try something like
[@"hello" drawAtPoint:CGPointZero withAttributes:attrs]from a background thread.