Thanks, but I'm not updating the UI; I'm resizing an image into an offscreen bitmap. Also, it takes too long to do the resize (~2 seconds) to run on the main thread; it's unacceptable to shut the interface down that long.
However, I think I have mostly solved the problem. It looks to me like you can do this safely in a background thread as long as you use only Core Graphics calls, and not the UI calls. UIGraphicsBeginImageContext() does indeed push a new CG context onto a stack, which is a problem.
But by explicitly calling CGBitmapContextCreate(), CGContextDrawImage(), and CGBitmapContextCreateImage(), you can resize the image without messing with the UIKit's graphics context stack.
The problem now is dealing with the damn imageOrientation field of the image, which seems to be handled automatically when you use the UIKit.
Also it took me a while to realize that if I wanted to get meaningful values in this field for images taken from the camera in-app, I had to first enable device orientation notifications.
|