Reputation: 4271
I am taking the screenshot of the app window on user's tap action using the following code:
UIGraphicsBeginImageContextWithOptions(self.view.window.bounds.size, self.view.opaque, 0.0);
[self.view.window.layer renderInContext:UIGraphicsGetCurrentContext()];
CGImageRef imageRef = CGImageCreateWithImageInRect([UIGraphicsGetImageFromCurrentImageContext() CGImage], CGRectMake(0, 0, 640, self.view.window.layer.frame.size.height *2));
-performing a few operations on imageContext
-
myImage = UIGraphicsGetImageFromCurrentImageContext();
Now, the screenshot is just fine, but the amount of time it takes to render it is excruciating. I need to present an animation as soon as the user taps, but i cannot begin the animation until the screenshot image is stored in myImage
.
Is there a speedy way of doing this, like Facebook does on it's wall (when image browser is opened), or are they using some other technique?
Upvotes: 2
Views: 119
Reputation: 4271
I managed to speed up the process a 'little' bit by distributing the tasks between the background and main threads.
I performed the following tasks on the background thread dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
//code
});
:
CGImageContext
CGImageRef
renderInContext
UIImage
to a selector
, which further sets the image to the variable i want (UIImageView
in my case) .In the selector
in invoked at the end of the block, i set the image to the UIImageView
using dispatch_async(dispatch_get_main_queue(), ^{
//code
});
Upvotes: 1