I am trying to convert my UIView into UIImage using below code.
+ (UIImage *) imageWithView:(UIView *)view{
float scale = 1.0f;
UIGraphicsBeginImageContextWithOptions(view.bounds.size, YES, scale);
[view.layer renderInContext:UIGraphicsGetCurrentContext()];
UIImage* img = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
view.layer.contents = nil;
return img;
}
There are two problem with this code.
1. When I run this code in background thread(!mainThread)
I faced memory leak problem when renderInContext is called in background thread.
2. When I run this code on Main thread
There is no memory leak but on iPad 3 I am facing some performance issue (my UI hangs when this method is called) while creating image from UIView. As I need to call this function more than 5 times in a seconds so UI hangs gives very bad user experience.
Please guide me if I am doing some thing wrong here?