I am using the function below to render a view as image. The problem is that for images with size over 2000px the memory pressure is too high and the App crashes. On the simulator it works fine at any size but on the iPad (2 or higher) the memory grows over 80MB.
Is there any "smart" way to render large views?
-(UIImage*)renderToImageUsingContextFixedScale{
UIImage*im2;
CGFloat scale = 1.0;
if(UIGraphicsBeginImageContextWithOptions != NULL)
{
if(scale > 1.0) {
UIGraphicsBeginImageContextWithOptions(self.frame.size, NO, scale);
} else {
UIGraphicsBeginImageContextWithOptions(self.frame.size, NO, scale);
}
} else {
UIGraphicsBeginImageContext(self.frame.size);
}
//::::::::::::::::
CGContextScaleCTM(UIGraphicsGetCurrentContext(), scale, scale);
//::::::::::::::::
@autoreleasepool {
[self.layer renderInContext:UIGraphicsGetCurrentContext()];
im2 = UIGraphicsGetImageFromCurrentImageContext();
///THE ERROR OCCURS HERE:
UIGraphicsEndImageContext();
}
//:::::::::::::::::::::::::::
return im2;
}