Skip to content

Instantly share code, notes, and snippets.

@akhenakh
Last active December 24, 2015 09:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save akhenakh/6776366 to your computer and use it in GitHub Desktop.
Save akhenakh/6776366 to your computer and use it in GitHub Desktop.
Core Graphics rendering from another thread
- (UIImage *)renderInImageOfSize:(CGSize)size;
{
UIGraphicsBeginImageContextWithOptions(size, NO, 0);
// do drawing here
UIImage *result = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
return result;
}
UIImageView *view; // assume we have this
NSOperationQueue *renderQueue; // assume we have this
CGSize size = view.bounds.size;
[renderQueue addOperationWithBlock:^(){
UIImage *image = [renderer renderInImageOfSize:size];
[[NSOperationQueue mainQueue] addOperationWithBlock:^(){
view.image = image;
}];
}];
@akhenakh
Copy link
Author

akhenakh commented Oct 1, 2013

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment