我有一个非常适合旋转图像的方法实现。唯一的问题是它一直在控制台中导致内存警告,并且由于内存压力导致我的应用程序崩溃。
我需要找到一种新方法,可以达到相同的结果,但不会导致内存问题或应用程序崩溃。
这是我现在正在使用的方法实现:
-(UIImage*) rotate:(UIImage*) src andOrientation:(UIImageOrientation)orientation
{
UIGraphicsBeginImageContext(src.size);
CGContextRef context=(UIGraphicsGetCurrentContext());
if (orientation == UIImageOrientationRight) {
CGContextRotateCTM (context, 90/180*M_PI) ;
} else if (orientation == UIImageOrientationLeft) {
CGContextRotateCTM (context, -90/180*M_PI);
} else if (orientation == UIImageOrientationDown) {
// NOTHING
} else if (orientation == UIImageOrientationUp) {
CGContextRotateCTM (context, 90/180*M_PI);
}
[src drawAtPoint:CGPointMake(0, 0)];
UIImage *img=UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
return img;
}
导致90%内存问题的具体说法是:
[src drawAtPoint:CGPointMake(0, 0)];
因此,解决方案可能是该语句的替代品,或者是全新的方法实现。
谢谢您的帮助。