iOS: How to Resize and Rotate an UIImage - Thread Safe Version
Here are two code snippets for rotating and resizing UIImage’s without using UIGraphicsBeginImageContext(), because it is not thread-safe and can lead to weird behavior.
In my case the camera-preview when taking a picture in an app I was writing, turned black from time to time. The problem was that I was rotating and resizing the images using UIGraphicsBeginImageContext().
Here’s some code I’ve found and tweaked to resize images:
And here’s how to rotate them:
Because the above takes radians, convert using something like this:
Just put these methods into a category on UIImage.